Fixed enum delegate

This commit is contained in:
Alexander Nozik 2019-10-07 13:27:54 +03:00
parent 3ff3a5d09e
commit 156a43d4bf
2 changed files with 4 additions and 3 deletions

View File

@ -242,7 +242,7 @@ val MetaItem<*>?.long get() = number?.toLong()
val MetaItem<*>?.short get() = number?.toShort()
inline fun <reified E : Enum<E>> MetaItem<*>?.enum() = if (this is ValueItem && this.value is EnumValue<*>) {
this.value as E
this.value.value as E
} else {
string?.let { enumValueOf<E>(it) }
}

View File

@ -1,6 +1,7 @@
package hep.dataforge.meta
import org.junit.Test
import kotlin.test.Test
class MetaExtensionTest {
@ -15,7 +16,7 @@ class MetaExtensionTest {
}
@Test
fun testEnumByString(){
val meta = buildMeta{"enum" to TestEnum.test.toString()}
val meta = buildMeta{"enum" to TestEnum.test.name}
println(meta["enum"].enum<TestEnum>())
}