Add support for null values

This commit is contained in:
Shadowfacts 2017-08-20 16:17:04 -04:00
parent a444838bf9
commit b8d4debfb7
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
1 changed files with 8 additions and 4 deletions

View File

@ -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 {
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)
}