is there a way to access attributes of an object d...
# announcements
c
is there a way to access attributes of an object dynamically for example
Copy code
class Bar {
   baz: String
   zab: String
}

class Foo {
    attributes: Bar()
}
Copy code
var foo = Foo()

for(attr in foo.atributes) {
    println("$attr") 
    // baz
    // zab
}
I’m looking at using kotlin-reflection lib and when i use
this.condiments::class.members
, i can see the attributes with a bunch of metadata, but i cant get the value.
Copy code
var foo = Foo()

for(attr in foo.atributes::class.members) {
    println("$attr") 
    // baz
    // zab
}
y
This should do the trick:
Copy code
for(attr in foo.attributes::class.memberProperties) {
    println("${(attr as KProperty1<Bar, Any>).get(foo.attributes)}")
}
c
work beautifully, thanks!