findKindByName method
Finds kind by name
.
Implementation
Kind<T> findKindByName(String name) {
for (var possibleKind in defaultKinds) {
if (possibleKind.name == name) {
return possibleKind;
}
}
if (!isSealed) {
for (var possibleKind in Kind.all) {
if (possibleKind.name == name && possibleKind is Kind<T>) {
return possibleKind;
}
}
}
if (!isRunningInDebugMode) {
throw ArgumentError.value(name, 'name', 'Unknown kind name.');
}
// Build list of possible names
final foundNames = <String>{};
for (var possibleKind in defaultKinds) {
foundNames.add(possibleKind.name);
}
for (var possibleKind in Kind.all) {
if (possibleKind is Kind<T>) {
foundNames.add(possibleKind.name);
}
}
if (foundNames.isEmpty) {
throw ArgumentError(
'JSON object field "$jsonDiscriminator" value "$name" is unsupported.\n\n'
'You have not registered any matching kinds with `Kind.registerAll(..)`.',
);
}
throw ArgumentError(
'JSON object field "$jsonDiscriminator" value "$name" is unsupported.\n\n'
'Supported values are: ${foundNames.map((e) => '"$e"').join(', ')}',
);
}