Parse<T> static method
Parses specified value based on type.
The value.
Implementation
static T? Parse<T>(String? value) {
if (possibleEnumsConverter.containsKey(T)) {
return possibleEnumsConverter[T]!(value) as T?;
} else if (schemaToEnumDictionaries.Member!.containsKey(T)) {
return schemaToEnumDictionaries.Member![T]![value!] as T?;
} else if (T == int) {
return int.parse(value!) as T;
} else if (T == double) {
return double.parse(value!) as T;
} else if (T == String) {
return value as T?;
} else if (T == bool) {
return (value!.toLowerCase() == "true") as T;
} else if (T == DateTime) {
return DateTime.parse(value!) as T;
} else {
throw NotImplementedException("Parse<$T>($value)");
}
// //todo("implement Parse<T>")
// print("implement Parse<T where ${T.runtimeType}>");
// if (typeof(T).IsEnum)
// {
// Dictionary<string, Enum> stringToEnumDict;
// Enum enumValue;
// if (schemaToEnumDictionaries.Member.TryGetValue(typeof(T), out stringToEnumDict) &&
// stringToEnumDict.TryGetValue(value, out enumValue))
// {
// // This double-casting is ugly, but necessary. By this point, we know that T is an Enum
// // (same as returned by the dictionary), but the compiler can't prove it. Thus, the
// // up-cast before we can down-cast.
// return (T)((object)enumValue);
// }
// else
// {
// return (T)Enum.Parse(typeof(T), value, false);
// }
// }
// else
// {
// return (T)Convert.ChangeType(value, typeof(T), CultureInfo.InvariantCulture);
// }
}