isInstanceOf<T> static method

void isInstanceOf<T>(
  1. Object? obj,
  2. String message
)

Asserts that the given obj is an instance of type T.

Throws an InvalidArgumentException with the given message if the object is not of the expected type.

Example:

Assert.isInstanceOf<String>(value, 'Expected a String');

Implementation

static void isInstanceOf<T>(Object? obj, String message) {
  if (obj is! T) {
    throw InvalidArgumentException(message);
  }
}