Get Default Constructor - CSharp System.Reflection

CSharp examples for System.Reflection:Constructor

Description

Get Default Constructor

Demo Code


using System.Reflection;
using System.Collections.Generic;
using System;/*from ww w  .j a va  2  s  .  co m*/

public class Main{
        public static ConstructorInfo GetDefaultConstructor(Type type)
        {
            ConstructorInfo constructor = type.GetConstructor(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[0], null);
            if (constructor == null)
            {
                throw new JsonException(type.FullName + " must have a parameterless constructor");
            }
            return constructor;
        }
}

Related Tutorials