Nir
07/15/2020, 2:21 PMfor (x in foo::class.memberProperties)
, but this only allows you to iterate over properties, i.e. no set function is availableGunslingor
07/15/2020, 3:00 PMNir
07/15/2020, 3:04 PMNir
07/15/2020, 3:04 PMGunslingor
07/15/2020, 3:05 PMNir
07/15/2020, 3:05 PMfor (x in p.memberProperties) {
println("${x.name}: ${x.get(person)}")
when (x.returnType) {
String::class -> (x as KMutableProperty1<Person, String>).set(person, "hello")
Int::class -> (x as KMutableProperty1<Person, Int>).set(person, 5)
}
}
Nir
07/15/2020, 3:05 PMNir
07/15/2020, 3:06 PMHow does one iterate over the mutable properties of a class
Gunslingor
07/15/2020, 3:09 PMGunslingor
07/15/2020, 3:10 PMNir
07/15/2020, 3:10 PMNir
07/15/2020, 3:10 PMGunslingor
07/15/2020, 3:11 PMNir
07/15/2020, 3:11 PMNir
07/15/2020, 3:12 PMif (not (x is KMutableProperty)) { continue }
Gunslingor
07/15/2020, 3:12 PMNir
07/15/2020, 3:13 PM