Ejemplo n.º 1
0
 /// <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;
     }
 }
Ejemplo n.º 2
0
	    public TsProperty(TsName name, TsType type, ISymbol symbol, bool optional = false)
		    : base(name)
	    {
		    Type = type;
		    Optional = optional;
		    Symbol = symbol;

		}
Ejemplo n.º 3
0
 /// <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);
 }
Ejemplo n.º 4
0
        /// <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);
        }
Ejemplo n.º 5
0
        /// <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));
        }
Ejemplo n.º 6
0
 /// <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;
 }
Ejemplo n.º 7
0
 /// <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);
 }
Ejemplo n.º 8
0
 /// <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);
 }
Ejemplo n.º 9
0
 /// <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)
 {
 }
Ejemplo n.º 10
0
 /// <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));
 }
Ejemplo n.º 11
0
 /// <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);
 }
Ejemplo n.º 12
0
 /// <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;
 }