castCollection method
Cast o
to a collection represented by typeInfo
.
- If
nullable
istrue
casts to a collection of nullable values. - See: castList, castSet, castIterable, castMap.
Implementation
Object? castCollection(dynamic o, TypeInfo typeInfo,
{bool nullable = false}) {
if (o == null) return null;
var mainType = typeInfo.argumentType(0) ?? typeInfo;
if (typeInfo.isSet) {
return castSet(o, mainType.type, nullable: nullable);
} else if (typeInfo.isList) {
return castList(o, mainType.type, nullable: nullable);
} else if (typeInfo.isIterable) {
return castIterable(o, mainType.type, nullable: nullable);
} else if (typeInfo.isMap) {
return castMap(o, typeInfo, nullable: nullable);
}
return null;
}