maybeFindByType<T> static method
Finds a registered kind for T
.
First he method inspects whether T
is equal to one of the registered
kinds in Kind.all.
If no kind was found, the method inspects whether T
is a list type of
one of the registered kinds in Kind.all.
If no kind was found, the method inspects whether T
is a set type of one
of the registered kinds in Kind.all.
Note that if a kind is found and T
is nullable, the method returns a
NullableKind.
Implementation
static Kind<T>? maybeFindByType<T>() {
if (T == Null) {
return Kind.forNull as Kind<T>;
}
if (0.0 is T) {
if (false is T) {
if (null is T) {
// T = `Object?`
const Kind anyKind = NullableKind(PolymorphicKind<Object>());
if (anyKind is Kind<T>) {
return anyKind;
}
}
// T = `Object`
const Kind objectKind = PolymorphicKind<Object>();
if (objectKind is Kind<T>) {
return objectKind;
}
} else if (null is T) {
// T = `double?`
const Kind doubleKind = NullableKind(Kind.forDouble);
if (doubleKind is Kind<T>) {
return doubleKind;
}
// T = `int?`
const Kind intKind = NullableKind(Kind.forInt);
if (intKind is Kind<T>) {
return intKind;
}
} else {
// T = `double`
const Kind doubleKind = Kind.forDouble;
if (doubleKind is Kind<T>) {
return doubleKind;
}
// T = `int`
const Kind intKind = Kind.forInt;
if (intKind is Kind<T>) {
return intKind;
}
}
}
if (null is T) {
for (var kind in _nullableKinds) {
if (kind.dartType == T) {
return kind as Kind<T>;
}
}
for (var item in _kinds) {
final kind = item.toList().toNullable();
if (kind.dartType == T) {
return kind as Kind<T>;
}
}
for (var item in _kinds) {
final kind = item.toSet().toNullable();
if (kind.dartType == T) {
return kind as Kind<T>;
}
}
} else {
for (var item in _kinds) {
final kind = item;
if (kind.dartType == T) {
return kind as Kind<T>;
}
}
for (var item in _kinds) {
final kind = item.toList();
if (kind.dartType == T) {
return kind as Kind<T>;
}
}
for (var item in _kinds) {
final kind = item.toSet();
if (kind.dartType == T) {
return kind as Kind<T>;
}
}
}
return null;
}