public create()

in lib/object-type.ts [77:102]


    public create(input: ObjectWithType | ObjectWithType[], context?: ObjectContext): any {
        if (input == null) {
            return null;
        }
        let typeName: string;
        if (Array.isArray(input)) {
            if ((<ObjectWithType[]>input).length == 0) {
                return [];
            }
            // It assumes that all items in array are the same type.
            typeName = (<ObjectWithType[]>input)[0]._type;
            for (let elem of input) {
                if (elem._type !== typeName) {
                    throw new Error("Property '_type' must be the same for all elements in input array when calling ObjectFactory.create.");
                }
            }
        }
        else {
            typeName = (<ObjectWithType>input)._type;
        }

        if (this.supports(typeName)) {
            return this._typeToFactoryMethod.get(typeName)(input, context);
        }
        throw new Error("Not supported type: '" + typeName + "'.");
    }