Skip to content

Instantly share code, notes, and snippets.

View asfdfdfd's full-sized avatar

Andrey Panchenko asfdfdfd

View GitHub Profile
inline fun <reified T : Any> setPropertyWithReflection(target: T, propertyName: String, propertyValue: Any) {
val namespaceMemberProperty = T::class.memberProperties
.filter { it.visibility == KVisibility.PUBLIC }
.filterIsInstance<KMutableProperty<*>>()
.firstOrNull { it.name == propertyName }
if (namespaceMemberProperty == null) {
throw NullPointerException("Failed to find '$propertyName' at '$target'.")
}