/// <summary> /// Registers a type mapping /// </summary> /// <param name="tsType">The TypeScript type</param> /// <param name="type">The native type</param> private void RegisterTypeMapping(TsType tsType, ITypeSymbol type) { if (type.SpecialType == SpecialType.None) { TypeLookup[type] = tsType; } }
public TsProperty(TsName name, TsType type, ISymbol symbol, bool optional = false) : base(name) { Type = type; Optional = optional; Symbol = symbol; }
/// <summary> /// Registers custom type mapping /// </summary> /// <param name="tsType">The TypeScript type</param> /// <param name="type">The native type</param> /// <returns></returns> public Scripter WithTypeMapping(TsType tsType, Type type) { if (this.TypeLookup.ContainsKey(type)) { throw new ArgumentException("Mapping for " + type.FullName + " is already defined.", "type"); } this.TypeLookup[type] = tsType; return(this); }
/// <summary> /// Registers custom type mapping /// </summary> /// <param name="tsType">The TypeScript type</param> /// <param name="type">The native type</param> /// <returns></returns> public Scripter WithTypeMapping(TsType tsType, Type type) { var typeSymbol = _compilation.GetTypeByMetadataName(type.FullName); if (typeSymbol != null) { if (TypeLookup.ContainsKey(typeSymbol)) { throw new ArgumentException("Mapping for " + type.Name + " is already defined.", nameof(type)); } TypeLookup[typeSymbol] = tsType; } return(this); }
/// <summary> /// Formats a type /// </summary> /// <param name="tsType">The type</param> /// <returns>The string representation of the type</returns> public virtual string Format(TsType tsType) { if (tsType == null) { return(string.Empty); } if (tsType is TsGenericType) { return(Format((TsGenericType)tsType)); } var tsInterface = tsType as TsInterface; if (tsInterface != null && tsInterface.IsLiteral) { return(Format(tsInterface)); } return(ResolveTypeName(tsType.Name, tsType.IsExternallyDefined)); }
/// <summary> /// Registers a type mapping /// </summary> /// <param name="tsType">The TypeScript type</param> /// <param name="type">The native type</param> private void RegisterTypeMapping(TsType tsType, Type type) { this.TypeLookup[type] = tsType; }
/// <summary> /// Adds a type to be scripted /// </summary> /// <param name="tsType">The type</param> /// <param name="type">The .NET type</param> /// <returns>The scripter</returns> private Scripter AddType(TsType tsType, Type type) { this.AddType(tsType); this.RegisterTypeMapping(tsType, type); return(this); }
/// <summary> /// Adds a type to be scripted /// </summary> /// <param name="tsType">The type</param> /// <returns>The scripter</returns> public Scripter AddType(TsType tsType) { this.Types.Add(tsType); return(this); }
/// <summary> /// Constructor /// </summary> /// <param name="elementType">The element type</param> /// <param name="dimensions">The dimensions</param> public TsArray(TsType elementType, int dimensions) : base(new TsName(elementType.Name.Name + GenerateArrayNotation(dimensions), elementType.Name.Namespace), PrimitiveType.Array) { }
/// <summary> /// Formats a return type /// </summary> /// <param name="tsReturnType">The return type</param> /// <returns>The string representation of the return type</returns> public virtual string FormatReturnType(TsType tsReturnType) { return(Format(tsReturnType)); }
/// <summary> /// Adds a type to be scripted /// </summary> /// <param name="tsType">The type</param> /// <param name="type">The .NET type</param> /// <returns>The <see cref="Scripter"/></returns> private Scripter AddType(TsType tsType, ITypeSymbol type) { AddType(tsType); RegisterTypeMapping(tsType, type); return(this); }
/// <summary> /// Constructor /// </summary> /// <param name="name">The parameter name</param> /// <param name="type">The parameter type</param> public TsParameter(TsName name, TsType type) : base(name) { this.Type = type; this.Optional = false; }