Browse Source

Add support for null values

master
Shadowfacts 4 years ago
parent
commit
b8d4debfb7
Signed by: shadowfacts GPG Key ID: 94A5AB95422746E5
  1. 12
      src/main/kotlin/net/shadowfacts/ekt/EKT.kt

12
src/main/kotlin/net/shadowfacts/ekt/EKT.kt

@ -234,15 +234,19 @@ _result.toString()
class DataProvider {
internal val map = mutableMapOf<String, TypedValue>()
infix fun String.to(value: Any) {
infix fun String.to(value: Any?) {
if (value is TypedValue) {
map[this] = value
} else {
map[this] = TypedValue(value, value::class.qualifiedName!!)
if (value == null) {
throw RuntimeException("Must provide explicit type for 'null' value")
} else {
map[this] = TypedValue(value, value::class.qualifiedName!!)
}
}
}
infix fun Any.asType(type: String): TypedValue {
infix fun Any?.asType(type: String): TypedValue {
return TypedValue(this, type)
}
@ -255,6 +259,6 @@ _result.toString()
}
}
data class TypedValue(val value: Any, val type: String)
data class TypedValue(val value: Any?, val type: String)
}
Loading…
Cancel
Save