예제 #1
0
 internal TypeScriptFluentModuleMember(TypeScriptFluent fluentConfigurator, TsModuleMember member)
     : base(fluentConfigurator)
 {
     this.Member = member;
 }
예제 #2
0
        private static void ProcessTypes(IEnumerable <Type> types, TypeScriptFluent generator)
        {
            foreach (var clrType in types.Where(t => t != typeof(void)))
            {
                if (generator.ModelBuilder.ContainsType(clrType))
                {
                    continue;
                }

                var clrTypeToUse = clrType;
                if (typeof(Task).GetDnxCompatible().IsAssignableFrom(clrTypeToUse))
                {
                    if (clrTypeToUse.GetDnxCompatible().IsGenericType)
                    {
                        clrTypeToUse = clrTypeToUse.GetDnxCompatible().GetGenericArguments()[0];
                    }
                    else
                    {
                        continue;  // Ignore non-generic Task as we can't know what type it will really be
                    }
                }

                if (clrTypeToUse.IsNullable())
                {
                    clrTypeToUse = clrTypeToUse.GetUnderlyingNullableType();
                }

                // Ignore compiler generated types
                if (clrTypeToUse.GetDnxCompatible().GetCustomAttribute(typeof(CompilerGeneratedAttribute)) != null)
                {
                    continue;
                }

                if (clrTypeToUse.Namespace.StartsWith("System"))
                {
                    continue;
                }

                if (clrTypeToUse.IsIDictionary())
                {
                    continue;
                }

                if (clrTypeToUse == typeof(string) || clrTypeToUse.GetDnxCompatible().IsPrimitive || clrTypeToUse == typeof(object))
                {
                    continue;
                }


                bool           isClassOrArray = clrTypeToUse.GetDnxCompatible().IsClass || clrTypeToUse.GetDnxCompatible().IsInterface;
                TsModuleMember member         = null;
                if (clrTypeToUse.IsArray)
                {
                    ProcessTypes(new[] { clrTypeToUse.GetElementType() }, generator);
                }
                else if (clrTypeToUse.GetDnxCompatible().IsGenericType)
                {
                    ProcessTypes(clrTypeToUse.GetDnxCompatible().GetGenericArguments(), generator);
                    bool isEnumerable = typeof(IEnumerable).GetDnxCompatible().IsAssignableFrom(clrTypeToUse);
                    if (!isEnumerable)
                    {
                        member = generator.ModelBuilder.Add(clrTypeToUse, !isClassOrArray);
                    }
                }
                else
                {
                    member = generator.ModelBuilder.Add(clrTypeToUse, !isClassOrArray);
                }

                var classModel = member as TsClass;
                if (isClassOrArray && classModel != null)
                {
                    var references = classModel.Properties
                                     .Where(model => !model.IsIgnored)
                                     .Select(m => m.PropertyType)
                                     .Concat(classModel.GenericArguments)
                                     .Select(m => m.Type)
                                     .Where(t => !t.IsIDictionary())
                                     .ToArray();

                    ProcessTypes(references, generator);
                }
            }
        }