public static Method CreateMethod(MethodInfo methodInfo, TsType parent) { var method = new Method(methodInfo.Name, parent) { IsStatic = methodInfo.IsStatic }; var parameters = methodInfo.GetParameters(); foreach (var parameterInfo in parameters) { method.Parameters.Add(MethodParameterFactory.Create(parameterInfo, method)); } if (methodInfo.IsGenericMethod) { var genericArguments = methodInfo.GetGenericArguments(); foreach (var argument in genericArguments) { method.Generics.Add(new GenericDefinition(argument.Name)); } } if (methodInfo.ReturnType != typeof(void)) { method.Return = new TsUndefined { UnderlyingType = methodInfo.ReturnType }; } return method; }
public Module(TsType parent, string name) : base(parent, name) { Name = name; Types = new List<TsType>(); Modules = new List<Module>(); }
public static TsType CreateClass(TsType parent, Type type) { var name = type.Name; var newClass = new Class(parent, name); if (type.IsGenericType) { var genericWartIndex = name.IndexOf("`"); if (genericWartIndex > 0) { newClass.Name = name.Substring(0, genericWartIndex); } var generics = type.GetGenericArguments(); foreach (var generic in generics) { newClass.Generics.Add(new GenericDefinition(generic.Name)); } } AddConstructors(type, newClass); AddFields(type, newClass); AddProperties(type, newClass); AddMethods(type, newClass); return newClass; }
public Method(string name, TsType parent) { Name = name; Parent = parent; Generics = new List<TsType>(); Parameters = new List<MethodParameter>(); }
public static Constructor Create(ConstructorInfo constructorInfo, TsType parent) { var constructor = new Constructor(parent); foreach (var parameterInfo in constructorInfo.GetParameters()) { constructor.Parameters.Add(MethodParameterFactory.Create(parameterInfo, constructor)); } return constructor; }
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 bool Matches(TsType type) { if (type == this) return true; if (type == null) return false; if (type.UnderlyingType == UnderlyingType && type.UnderlyingType != null) return true; return false; }
public static TsType CreateEnum(TsType parent, Type type) { var typeName = type.Name; var newEnum = new TypeScript.Enum(parent, typeName); var names = System.Enum.GetNames(type); var typeCode = Type.GetTypeCode(System.Enum.GetUnderlyingType(type)); foreach (var enumName in names) { var val = System.Enum.Parse(type, enumName); var i = Convert.ChangeType(val, typeCode); newEnum.Values.Add(new EnumValue(enumName, Convert.ToInt64(i))); } return newEnum; }
public void ResolveTypes(TypeResolver typeResolver) { foreach (var generic in Generics) { generic.ResolveTypes(typeResolver); } foreach (var methodParameter in Parameters) { methodParameter.ResolveTypes(typeResolver); } if (Return != null) { Return = typeResolver.GetType(Return.UnderlyingType, Parent); } }
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; }
public virtual bool IsBetterThan(TsType otherType) { return true; }
protected TsType(TsType parent, string name) { Parent = parent; Name = name; }
public Field(string name, TsType parent) { Name = name; Parent = parent; }
public void ResolveTypes(TypeResolver typeResolver) { Type = typeResolver.GetType(Type.UnderlyingType, Method.Parent); }
public Constructor(TsType parent) : base("", parent) { }
public Enum(TsType parent, string name) : base(parent, name) { Values = new List<EnumValue>(); }