to<T> method
T
to<T>()
Convert this expression to a T
.
This supports the following types:
Implementation
T to<T>() {
if (this is T) {
return this as T;
} else if (T == int) {
return toInt() as T;
} else if (T == BigInt) {
return toBigInt() as T;
} else if (T == Rat) {
return toRat() as T;
} else if (T == double) {
return toDouble() as T;
} else if (T == String) {
return toString() as T;
} else if (T == bool) {
return toBool() as T;
} else if (this is ConstVar && <T>[] is List<Enum>) {
final m = _declaredEnums[currentContext];
if (m != null && m.containsKey(T)) {
final name = ((this as ConstVar).decl.name as StringSym).value;
return m[T]!.$1.firstWhere((e) => e.name == name) as T;
} else {
throw ArgumentError.value(
T,
'T',
'not declared, try using declareEnumValues',
);
}
}
throw ArgumentError.value(this, 'this', 'cant be converted to $T');
}