public override void Process(IEnumerable <Assembly> input)
        {
            base.Process(input);

            Types = Types.OrderBy((arg) => arg.Type.FullName).OrderBy((arg) => Types.HasClass(arg.Type.BaseType)).ToList();
            Console.WriteLine($"\t{Types.Count} types found");

            // proceed with extra adjustments before giving results to the generator
            foreach (var t in Types)
            {
                foreach (var uctor in GetUnavailableParentCtors(t))
                {
                    var c = new ProcessedConstructor(uctor.Constructor, this)
                    {
                        Unavailable = true
                    };
                    t.Constructors.Add(c);
                }
            }

            // we want to create wrappers only if the signature does not already exists, e.g. both `.ctor ()` and `.ctor (int i = 0)` can co-exists in .net
            foreach (var dv in members_with_default_values)
            {
                var pt = GetProcessedType(dv.DeclaringType);
                var ci = dv as ConstructorInfo;
                if (ci != null)
                {
                    foreach (var pc in AddDefaultValuesWrappers(ci))
                    {
                        if (!pt.SignatureExists(pc))
                        {
                            pt.Constructors.Add(pc);
                        }
                        else
                        {
                            Delayed.Add(ErrorHelper.CreateWarning(1021, $"Constructor `{ci}` has default values for which no wrapper is generated."));
                        }
                    }
                    continue;
                }
                var mi = dv as MethodInfo;
                foreach (var pm in AddDefaultValuesWrappers(mi))
                {
                    if (!pt.SignatureExists(pm))
                    {
                        pt.Methods.Add(pm);
                    }
                    else
                    {
                        Delayed.Add(ErrorHelper.CreateWarning(1032, $"Method `{mi}` has default values for which no wrapper is generated."));
                    }
                }
            }

            ErrorHelper.Show(Delayed);
        }
예제 #2
0
        protected IEnumerable <ProcessedConstructor> PostProcessConstructors(IEnumerable <ConstructorInfo> constructors)
        {
            HashSet <string> duplicateNames = FindDuplicateNames(constructors);

            foreach (ConstructorInfo constructor in constructors)
            {
                ProcessedConstructor processedConstructor = new ProcessedConstructor(constructor, this);

                if (duplicateNames.Contains(CreateStringRep(constructor)))
                {
                    processedConstructor.FallBackToTypeName = true;
                }

                yield return(processedConstructor);
            }
        }
        IEnumerable <ProcessedConstructor> AddDefaultValuesWrappers(ConstructorInfo ci)
        {
            // parameters with default values must be at the end and there can be many of them
            var parameters = ci.GetParameters();

            for (int i = parameters.Length - 1; i >= 0; i--)
            {
                if (!parameters [i].HasDefaultValue)
                {
                    continue;
                }
                var pc = new ProcessedConstructor(ci, this)
                {
                    ConstructorType       = ConstructorType.DefaultValueWrapper,
                    FirstDefaultParameter = i,
                };
                yield return(pc);
            }
        }