extractGenericPart static method

String extractGenericPart(
  1. String typeString
)

Extracts the inner generic type parameters from a type string.

Parameters:

  • typeString: The type string to parse (e.g., List<String>)

Returns:

  • The inner generic part (e.g., String from List<String>)
  • Empty string if no generic parameters exist

Example:

final inner = GenericTypeParser.extractGenericPart('List<String>');
print(inner); // 'String'

final nested = GenericTypeParser.extractGenericPart('Map<String, List<int>>');
print(nested); // 'String, List<int>'

Implementation

static String extractGenericPart(String typeString) {
  final startIndex = typeString.indexOf('<');
  final endIndex = typeString.lastIndexOf('>');

  if (startIndex == -1 || endIndex == -1 || startIndex >= endIndex) {
    return '';
  }

  return typeString.substring(startIndex + 1, endIndex);
}