vmironov
03/29/2016, 2:18 PMinline operator fun <reified V : Any> SharedPreferences.getValue(thisRef: Any?, property: KProperty<*>): V {
return getValue(thisRef, property, V::class.java)
}
fun <V> SharedPreferences.getValue(thisRef: Any?, property: KProperty<*>, clazz: Class<V>): V {
return clazz.cast(when (clazz) {
String::class -> getString(name, "") as V
Int::class -> getInt(name, 0) as V
Float::class -> getFloat(name, 0F) as V
Long::class -> getLong(name, 0L) as V
Boolean::class -> getBoolean(name, false) as V
else -> throw IllegalArgumentException("This Type[${V::class.java.simpleName} is not supported by SharedPreferences")
})
}