Get Public Or Protected Constructors from Type - CSharp System.Reflection

CSharp examples for System.Reflection:ConstructorInfo

Description

Get Public Or Protected Constructors from Type

Demo Code


using System.Linq.Expressions;
using System.Reflection;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;//from www . jav  a2s .co m

public class Main{
        public static ConstructorInfo[] GetPublicOrProtectedConstructors(Type t)
        {
            var cs = t.GetConstructors(InstanceFlag);
            var list = new List<ConstructorInfo>();
            foreach (ConstructorInfo info in cs)
            {
                if (info.IsPublic || info.IsFamily)
                {
                    list.Add(info);
                }
            }
            return list.ToArray();
        }
}

Related Tutorials