to<E, T> method

E to<E, T>(
  1. E toe(
    1. 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);
}