ClassUtils class final

A utility class that provides static methods for working with class hierarchies and type relationships in Dart's reflection system.

This class offers functionality to traverse and analyze class inheritance structures, including superclasses, interfaces, and special handling for arrays and enums.

Usage

// Get the complete class hierarchy for a type
final hierarchy = ClassUtils.getClassHierarchy(Class.of<String>());

// The hierarchy will include:
// - The original class (String)
// - All superclasses up to Object
// - All implemented interfaces
// - Special handling for arrays and enums

print('Class hierarchy for String:');
for (final clazz in hierarchy) {
  print('  ${clazz.getName()}');
}

Features

  • Complete hierarchy traversal: Walks up the entire inheritance chain
  • Interface inclusion: Includes all implemented interfaces at each level
  • Array support: Special handling for array component types
  • Enum support: Proper enum hierarchy with Enum base class
  • Duplicate prevention: Ensures no duplicate classes in the hierarchy
  • Ordered results: Returns hierarchy in a logical traversal order

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

findMethodCandidatesByName(Class clazz, String methodName) Set<Method>
Retrieves the set of methods with the specified name from the given class.
getClassHierarchy(Class type) List<Class>
Retrieves the complete class hierarchy for the specified type, including all superclasses, interfaces, and special type relationships.
getMethodIfAvailable(Class clazz, String methodName, [List<Class>? paramTypes]) Method?
Retrieves the method with the specified name and parameter types from the given class.
getMethodOrNull(Class clazz, String methodName, List<Class> paramTypes) Method?
Retrieves the method with the specified name and parameter types from the given class.
getStaticMethod(Class target, String methodName) Method?
Retrieves the static method with the specified name from the given class.
isAssignable(Class left, Class right) bool
Check if the right-hand side type may be assigned to the left-hand side type.

Constants

arrayTypeSuffix → const String
Suffix for array class names: "[]"
nestedClassSeparator → const String
The nested class separator character: '$'
packageSeparator → const String
The package separator character: '.'