isGeneric static method

bool isGeneric(
  1. String typeString
)

Determines if a type string contains generic parameters.

Parameters:

  • typeString: The type string to check

Returns:

  • true if the type has generic parameters
  • false for non-generic types

Example:

GenericTypeParser.isGeneric('List<String>'); // true
GenericTypeParser.isGeneric('String'); // false

Implementation

static bool isGeneric(String typeString) {
  if (!typeString.contains('<') || !typeString.contains('>')) {
    return false;
  }

  final openIndex = typeString.indexOf('<');
  final closeIndex = typeString.lastIndexOf('>');

  return openIndex < closeIndex && openIndex != -1 && closeIndex != -1;
}