Esempio n. 1
0
 public static TypeFullName FromString(string name)
 {
     return(TypeFullNameParser.Parse(name));
 }
Esempio n. 2
0
        public TypescriptType GetTypeScriptType(string typeFullName)
        {
            InterfaceType interfaceType;

            if (interfaceTypes.TryGetValue(typeFullName, out interfaceType))
            {
                return(interfaceType);
            }

            if (IsGenericEnumerable(typeFullName))
            {
                return(new ArrayType
                {
                    ElementType = GetTypeScriptType(UnwrapGenericType(typeFullName))
                });
            }
            else if (IsNullable(typeFullName))
            {
                return(new NullableType
                {
                    WrappedType = GetTypeScriptType(UnwrapGenericType(typeFullName))
                });
            }

            var realType = TypeFullNameParser.Parse(typeFullName);

            if (realType.IsEnumerable())
            {
                return(new ArrayType()
                {
                    ElementType = GetTypeScriptType(realType.TypeArgumentFullNames[0].FullName)
                });
            }
            else if (realType.IsDictionary())
            {
                return(new DictionaryType()
                {
                    KeyType = GetTypeScriptType(realType.TypeArgumentFullNames[0].FullName),
                    ElementType = GetTypeScriptType(realType.TypeArgumentFullNames[1].FullName)
                });
            }

            switch (typeFullName)
            {
            case "System.Guid":
                return(new GuidType());

            case "System.Boolean":
                return(new BoolType());

            case "System.Double":
            case "System.Int16":
            case "System.Int32":
            case "System.Int64":
            case "System.UInt16":
            case "System.UInt32":
            case "System.UInt64":
            case "System.Decimal":
            case "System.Byte":
            case "System.SByte":
            case "System.Single":
                return(new NumberType());

            case "System.String":
                return(new StringType());

            case "System.DateTime":
            case "System.DateTimeOffset":
                if (Settings.UseNativeDates)
                {
                    return(new DateTimeType());
                }
                else
                {
                    return(new StringType());
                }

            default:
                return(new TypescriptType());
            }
        }