示例#1
0
文件: Generator.cs 项目: omeaart/CSTS
        private TypeScriptType ProcessTypeScriptType(Type t, DictionaryType tst)
        {
            if (tst.ClrType.IsGenericType)
              {
            var args = tst.ClrType.GetGenericArguments();

            if (typeof(IDictionary).IsAssignableFrom(tst.ClrType) && args.Length == 2)
            {
              var keyTst = GetTypeScriptType(args[0]);

              tst.ElementKeyType = ProcessTypeScriptType(args[0], (dynamic)keyTst);

              var valueTst = GetTypeScriptType(args[1]);

              tst.ElementValueType = ProcessTypeScriptType(args[1], (dynamic)valueTst);
            }
              }

              return tst;
        }
示例#2
0
 private string GetTypeName(DictionaryType tst)
 {
     return string.Format("{{ [ key : {2}{0} ] : {3}{1} }}",
     GetTypeName((dynamic)tst.ElementKeyType), GetTypeName((dynamic)tst.ElementValueType),
     _moduleNameGenerator.GetModuleName((dynamic)tst.ElementKeyType), _moduleNameGenerator.GetModuleName((dynamic)tst.ElementValueType));
 }
示例#3
0
文件: Generator.cs 项目: omeaart/CSTS
        private TypeScriptType GetTypeScriptType(Type type)
        {
            TypeScriptType tst;

              if (TypeHelper.Is(type, typeof(string)))
              {
            tst = new StringType();
              }
              else if (TypeHelper.Is(type, typeof(bool)))
              {
            tst = new BooleanType();
              }
              else if (TypeHelper.Is(type, typeof(int),
                                        typeof(decimal),
                                        typeof(double),
                                        typeof(long),
                                        typeof(float),
                                        typeof(short),
                                        typeof(byte),
                                        typeof(uint),
                                        typeof(ushort),
                                        typeof(ulong),
                                        typeof(sbyte)
                                        ))
              {
            tst = new NumberType();
              }
              else if (TypeHelper.Is(type, typeof(DateTime)))
              {
            tst = new DateTimeType();
              }
              else if (TypeHelper.Is(type, typeof(TimeSpan)))
              {
            tst = new TimeSpanType();
              }
              else if (type.IsGenericParameter)
              {
            tst = new GenericTypeParameter();
              }
              else if (TypeHelper.IsDictionary(type))
              {
            tst = new DictionaryType();
              }
              else if (TypeHelper.IsEnumerable(type))
              {
            tst = new ArrayType();
              }
              else if (TypeHelper.IsEnum(type))
              {
            tst = new EnumType();
              }
              else
              {
            var processType = _options.TypeFilter(type);

            if (processType)
            {
              if (type.IsInterface)
              {
            tst = new InterfaceType(type);
              }
              else
              {
            tst = new CustomType(type);
              }
            }
            else
            {
              tst = new AnyType();
            }
              }

              if (TypeHelper.IsNullableValueType(type))
              {
            ((ValueType)tst).IsNullable = true;
            type = Nullable.GetUnderlyingType(type);
              }

              tst.ClrType = type;

              return tst;
        }