Skip to content

The type.gettypeconStructors method gets seven constructors in .Net Core #140

Open
@a764578566

Description

@a764578566

I use .net core 3.1 and .net 5 RC2

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using TinyIoC;

namespace ConsoleApp4
{
    class Program
    {
        static void Main(string[] args)
        {
            var personLazy = TinyIoCContainer.Current.Resolve<Lazy<Person>>();
            //var person = personLazy.Value;

            var candidateCtors = typeof(Lazy<Person>).GetConstructors(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
                 .Where(x => !x.IsPrivate) // Includes internal constructors but not private constructors
                 .Where(x => !x.IsFamily) // Excludes protected constructors
                 .ToList();

            var ctors = candidateCtors.OrderByDescending(ctor => ctor.GetParameters().Count());

            foreach (var ctor in ctors)
            {
                Console.WriteLine(ctor.ToString());
            }
            Console.ReadKey();
        }
    }

    class Person
    {
        public Person()
        {
            Console.WriteLine("new Person");
        }
    }
}

image

but The type.gettypeconStructors method gets six constructors in Framework 4.5
image

Causes the Resolve lazy object to be initialized
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions