castCollection method

Object castCollection(
  1. Object o, {
  2. bool nullable = false,
})

Casts o to this collection type if a ClassReflection or EnumReflection for it is registered at ReflectionFactory.

Implementation

Object castCollection(Object o, {bool nullable = false}) {
  if (isMap && o is Map) {
    return castMap(o, nullable: nullable);
  }

  var mainType = isCollection ? (argumentType(0) ?? TypeInfo.tDynamic) : this;

  var reflectionFactory = ReflectionFactory();

  var reflection =
      reflectionFactory.getRegisterClassReflection(mainType.type) ??
          reflectionFactory.getRegisterEnumReflection(mainType.type);

  if (reflection != null) {
    return reflection.castCollection(o, this, nullable: nullable) ?? o;
  }

  return o;
}