/// <summary> /// Formats a type parameter /// </summary> /// <param name="typeParameter">The type parameter</param> /// <returns>The string representaton of the type parameter</returns> public virtual string Format(TsTypeParameter typeParameter) { return(string.Format("{0}{1}", typeParameter.Name, typeParameter.Extends == null ? string.Empty : string.Format(" extends {0}", typeParameter.Extends.FullName))); }
public virtual string Format(TsTypeParameter typeParameter) { return string.Format("{0}{1}", typeParameter.Name, typeParameter.Extends == null ? string.Empty : string.Format(" extends {0}", typeParameter.Extends.FullName)); }
private TsInterface GenerateInterface(Type type) { var tsInterface = new TsInterface(GetName(type)); if (!this.TypeLookup.ContainsKey(type)) this.TypeLookup.Add(type, tsInterface); // resolve interfaces implemented by the type foreach (var interfaceType in type.GetInterfaces()) this.AddType(interfaceType); if (type.IsGenericType) { if (type.IsGenericTypeDefinition) { foreach (var genericArgument in type.GetGenericArguments()) { var tsTypeParameter = new TsTypeParameter(new TsName(genericArgument.Name)); var genericArgumentType = genericArgument.GetGenericParameterConstraints().FirstOrDefault(); if (genericArgumentType != null) { var tsTypeParameterType = Resolve(genericArgumentType); tsTypeParameter.Extends = tsTypeParameterType.Name; } tsInterface.TypeParameters.Add(tsTypeParameter); } } else { var genericType = type.GetGenericTypeDefinition(); var tsGenericType = this.Resolve(genericType); } } // resolve the base class if present if (type.BaseType != null) { var baseType = this.Resolve(type.BaseType); if (baseType != null && baseType != TsPrimitive.Any) tsInterface.BaseInterfaces.Add(baseType); } // process properties foreach (var property in this.Reader.GetProperties(type)) { tsInterface.Properties.Add(new TsProperty(GetName(property), Resolve(property.PropertyType))); } if (!IgnoreFunctions) { // process methods foreach (var method in this.Reader.GetMethods(type)) { var returnType = Resolve(method.ReturnType); var parameters = this.Reader.GetParameters(method); var tsFunction = new TsFunction(GetName(method)); tsFunction.ReturnType = returnType; if (method.IsGenericMethod) { foreach (var genericArgument in method.GetGenericArguments()) { var tsTypeParameter = new TsTypeParameter(new TsName(genericArgument.Name)); tsFunction.TypeParameters.Add(tsTypeParameter); } } foreach (var param in parameters.Select(x => new TsParameter(GetName(x), Resolve(x.ParameterType), IsOptionalParameter(x)))) { tsFunction.Parameters.Add(param); } tsInterface.Functions.Add(tsFunction); } } return tsInterface; }