to<E, T> method
E
to<E, T>(
- E toe(
- T e
Converts the value of the CborObject
to the specified type E
using the provided function toe
.
Throws a MessageException
if the value cannot be converted to type T
.
Implementation
E to<E, T>(E Function(T e) toe) {
if (this is T) {
return toe(this as T);
}
if (value is! T) {
throw MessageException("Failed to cast value.", details: {
"Value": "$value",
"Type": "$T",
});
}
return toe(value as T);
}