All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.gesellix.docker.compose.adapters.ReflectionUtil.kt Maven / Gradle / Ivy

package de.gesellix.docker.compose.adapters

import kotlin.reflect.KMutableProperty
import kotlin.reflect.full.declaredMemberProperties
import kotlin.reflect.full.memberProperties

fun  readProperty(instance: Any, propertyName: String): R {
    val clazz = instance.javaClass.kotlin
    @Suppress("UNCHECKED_CAST")
    return clazz.declaredMemberProperties.first { it.name == propertyName }.get(instance) as R
}

fun writeProperty(instance: Any, propertyName: String, value: Any?) {
    val clazz = instance.javaClass.kotlin
    @Suppress("UNCHECKED_CAST")
    return clazz.memberProperties
            .filterIsInstance>()
            .first { it.name == propertyName }.setter.call(instance, value)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy