Exemplo n.º 1
0
        private string GetGenericParameterName(GenericParameter p)
        {
            if (!p.GenericConstraints.Any())
              {
            return p.ClrGenericArgument.Name;
              }
              else
              {
            var arg = p.GenericConstraints.First();

            var recursive = false;

            // Is the constraint recursive? Not supported in TypeScript. Just return the generic arg without the constraint
            // https://typescript.codeplex.com/wikipage?title=Known%20breaking%20changes%20between%200.8%20and%200.9&referringTitle=Documentation
            if (arg.ClrType.IsGenericType && arg.ClrType.GetGenericArguments().Any(g => g == p.ClrGenericArgument))
            {
              recursive = true;
            }

            string value = string.Format("{0} extends {1}{2}", p.ClrGenericArgument.Name, _moduleNameGenerator.GetModuleName((dynamic)arg), GetTypeName((dynamic)arg));

            if (recursive)
            {
              value = value.Replace(string.Format("<{0}>", p.ClrGenericArgument.Name), "<any>").Replace(string.Format("{0}[]", p.ClrGenericArgument.Name), "any[]");
            }

            return value;
              }
        }
Exemplo n.º 2
0
        private void ProcessGenericConstraints(Type t, CustomType tst)
        {
            if (t.IsGenericTypeDefinition)
              {
            tst.GenericParameters = new List<GenericParameter>();

            foreach (var param in t.GetGenericArguments())
            {
              var genericParam = new GenericParameter()
              {
            GenericConstraints = new List<TypeScriptType>(),
            ClrGenericArgument = param
              };

              tst.GenericParameters.Add(genericParam);
              var constraints = param.GetGenericParameterConstraints();

              if (constraints.Any())
              {
            foreach (var constraint in constraints)
            {
              var constraintArg = ProcessTypeScriptType(constraint, (dynamic)GetTypeScriptType(constraint));

              genericParam.GenericConstraints.Add((TypeScriptType)constraintArg);
            }
              }
            }
              }
        }