Is it possible to directly obtain the delegate object in property delegation? Currently, I am using two properties because I can't directly get the delegate object. For example:
private var _x = dirtyValue(x)
var x by _x
fun <T> dirtyValue(value: T?, dirtyInit: Boolean = false) = DirtyDelegation(value, dirtyInit)
class DirtyDelegation<T> internal constructor(
var value: T?,
var dirty: Boolean
) {
operator fun getValue(thisRef: Any?, property: KProperty<*>): T? {
return value
}
operator fun setValue(thisRef: Any?, property: KProperty<*>, value: T?) {
this.value = value
this.dirty = true
}
}
This is what I do now, I have to use 2 properties because I can't get the delegate object
I want to access the dirty state, but
var x by dirtyValue
cannot do it