@kopper i think this is the worst kotlin i ever wrote fun loadProps() { this::cl...

@amy@sk.girlthi.ng

@kopper i think this is the worst kotlin i ever wrote

    fun loadProps() {
        this::class.declaredMemberProperties
            .mapNotNull { getDelegate(it) }
            .filterIsInstance<whenEnabled<*>>()
            .forEach { it.load() }
    }

    private fun <T> getDelegate(prop: KProperty<T>): Any? {
        return try {
            javaClass.getDeclaredField("${prop.name}\$delegate").let {
                it.isAccessible = true
                it.get(this)
            }
        }
        catch (exception: NoSuchFieldException) {
            null
        }
    }

used for basically deferred init through delegates with dependency management

16 year old me was mildly insane