Hi, I trying move project to IR, but I have issue with 'reflection'
Copy code
internal actual fun Any.getFieldValue(fieldName: String): Any? {
val thisDynamic: dynamic = this
return thisDynamic[fieldName]
}
this works well on LEGACY, but on IR it return undefined.
I try to play with that and
thisDynamic[fieldName+"_1"]
return right value, but I don't think this is safe solution.
This is any class, where I want to find value by string.
Is there any idea how to do it in IR?
r
Robert Jaros
03/17/2023, 10:30 AM
You can't. You need to think about alternative solutions for your use case. E.g. you can use kotlinx.serialization to serialize your kotlin object to json and then access json fields by string name.
👍 1
m
Michal Janos
03/17/2023, 10:40 AM
Yes, I trying find alternative solution, but why it work for legacy, but not for IR?