public static TsType Create(TsType parent, Type type) { TsType result = null; if (type.IsClass) { result = ClassFactory.CreateClass(parent, type); } else if (type.IsEnum) { result = EnumFactory.CreateEnum(parent, type); } else if (type == typeof(string)) { result = TsString.Instance; } else if (IsNumberType(type)) { result = TsNumber.Instance; } else if (type == typeof (char)) { result = TsString.Instance; } else if (type == typeof (bool)) { result = TsBoolean.Instance; } else if (type.IsArray) { result = new TsArray(type.GetElementType()); } else if (type == typeof(object)) { result = TsAny.Instance; } else if (type.IsValueType) { result = ClassFactory.CreateClass(parent, type); } else if (type.IsInterface) { result = ClassFactory.CreateClass(parent, type); } if (result != null) { Resolver.Types[type] = result; return result; } throw new UnsupportedTypeException(type); }
public TsType GetType(Type type, TsType parent = null) { if (TsTypeFactory.IsNumberType(type)) return TsNumber.Instance; if (type == typeof (string)) return TsString.Instance; if (type == typeof(bool)) return TsBoolean.Instance; if (type.IsArray) { var tsArray = new TsArray(type.GetElementType()); tsArray.ResolveTypes(this); return tsArray; } TsType tsType; if (Types.TryGetValue(type, out tsType)) { return tsType; } if (!type.IsGenericParameter) { return TsAny.Instance; } var parentClass = parent as Class; if (parentClass == null) { return TsAny.Instance; } // if the parent is generic we might have match. var generic = parentClass.Generics.SingleOrDefault(x => x.Name == type.Name); if (generic != null) { return new GenericDefinition(type.Name); } return TsAny.Instance; }