equalsAsType<T> method

bool equalsAsType<T>(
  1. TypeCode type,
  2. dynamic obj
)

Compares this object value to specified specified value. When direct comparison gives negative results it converts values to type specified by type code and compare them again.

  • obj the value to be compared with. Returns true when objects are equal and false otherwise.

See TypeConverter.toType

Implementation

bool equalsAsType<T>(TypeCode type, obj) {
  if (obj == null && _value == null) return true;
  if (obj == null || _value == null) return false;

  if (obj is AnyValue) obj = obj._value;

  var typedThisValue = TypeConverter.toType<T>(type, _value);
  var typedValue = TypeConverter.toType<T>(type, obj);

  if (typedThisValue == null && typedValue == null) return true;
  if (typedThisValue == null || typedValue == null) return false;
  return typedThisValue == typedValue;
}