castSet method
Cast set
to reflectedType if type
== reflectedType or return null
.
- If
nullable
istrue
casts to a Set of nullable values.
Implementation
Set? castSet(Set set, Type type, {bool nullable = false}) {
if (type == reflectedType) {
if (nullable) {
if (set is Set<O?>) {
return set;
} else {
return Set<O?>.from(set);
}
} else {
if (set is Set<O>) {
return set;
} else {
return Set<O>.from(set);
}
}
} else if (type == dynamic) {
return Set<dynamic>.from(set);
} else if (type == Object) {
return nullable ? Set<Object?>.from(set) : Set<Object>.from(set);
}
var typeInfo = TypeInfo.fromType(type);
Set? callCast<E>() => set.cast<E>();
Set? callCastNullable<E>() => set.cast<E?>();
var l = nullable
? typeInfo.callCasted(callCastNullable)
: typeInfo.callCasted(callCast);
return l;
}