parseValueForType<V> static method
Parses value
using a parserFor type
.
Returns value
if can't parse.
Implementation
static V? parseValueForType<V>(Type type, Object? value, [V? def]) {
if (value == null) return def;
var typeInfo = TypeInfo.from(type);
var valueTypeInfo = TypeInfo.from(value);
if (valueTypeInfo == typeInfo) {
return value as V;
}
var parser = parserFor(typeInfo: typeInfo);
if (parser != null) {
var parsed = parser(value);
return parsed ?? def;
} else {
return def;
}
}