# findComponentType<C> method

1. @override

Class<C>? findComponentType<C>(

1. Class parentClass,
2. Type? component

)
override

Finds the component type of a collection-like class.

Type Parameters:

- `C`: The expected component type.

Parameters:

- `parentClass`: The class representing the collection.
- `component`: The runtime Type to help narrow the match (optional).

Returns:

- A Class<C> representing the component type, or `null` if none exists.

## Example

    final listClass = await loader.loadClass<List<String>>('dart:core/list.dart.List');
    final stringType = loader.findComponentType<String>(listClass);
    print(stringType?.qualifiedName); // "dart:core/string.dart.String"

## Implementation

    @override
    Class<C>? findComponentType<C>(Class parentClass, Type? component) {
      _checkClosed();

      final cacheKey = "${_buildCacheKey(parentClass)}:${component ?? ""}:classComponent";

      // Check cache first
      final cached = _classComponentCache[cacheKey];
      if (cached != null) {
        _hitCount++;
        return cached as Class<C>;
      }

      _missCount++;

      component ??= extractComponentType(parentClass);

      Class<C>? result;
      if (component == null) {
        result = _extractComponentTypeFromName<C>(parentClass);
      } else if(component.toString().contains("dynamic") && !parentClass.getName().contains("dynamic")) {
        result = _extractComponentTypeFromName<C>(parentClass);
      } else {
        result = Class.forType<C>(component as C, parentClass.getProtectionDomain());
      }

      // Cache result
      if(result != null) {
        _classComponentCache[cacheKey] = result;
      }

      return result;
    }