castCollection method

Object? castCollection(
  1. dynamic o,
  2. TypeInfo typeInfo, {
  3. bool nullable = false,
})

Cast o to a collection represented by typeInfo.

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;
}