mercredi 28 septembre 2022

How to obtain extension properties by Kotlin reflection?

I have used the memberExtensionProperties() method, but result collection of the extension properties is empty. The test code is attached. What is the right procedure?

class ExtensionPropertyTest {
    class DummyClass{}
    val DummyClass.id get() = 99
    val DummyClass.name get() = "Joe"

    @Test
    fun testExtensionProperties() {
        val dummyClass = DummyClass()
        expect(dummyClass.id).toEqual(99) // OK

        val properties = DummyClass::class.memberExtensionProperties
            .stream()
            .toList()
        expect(properties).toHaveSize(2) // Fails due a zero size
    }
}




Aucun commentaire:

Enregistrer un commentaire