isArray method

bool isArray()

Determines whether this ResolvableType represents an array or list type.

In Dart, this method checks if the type represents a List or other array-like collection that has a component type.

Returns:

  • true if this type represents an array/list
  • false if this is not an array type

Example:

final listType = ResolvableType.forClass(List<String>);
final stringType = ResolvableType.forClass(String);
final setType = ResolvableType.forClass(Set<int>);

print(listType.isArray()); // true
print(stringType.isArray()); // false
print(setType.isArray()); // false (Set is not considered an array)

// Use in type processing
void processType(ResolvableType type) {
  if (type.isArray()) {
    final componentType = type.getComponentType();
    print("Processing array of ${componentType.resolve()?.getType()}");
  } else {
    print("Processing single value of ${type.resolve()?.getType()}");
  }
}

Implementation

bool isArray() {
  if (this == NONE) return false;

  final resolved = resolve();
  if (resolved != null) {
    return resolved.isArray();
  }

  return _type.toString().contains('List<') || _type == List;
}