Get Default Instance Of - CSharp System.Reflection

CSharp examples for System.Reflection:Constructor

Description

Get Default Instance Of

Demo Code


using System.Reflection;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;//from   w  w w  .ja  v  a  2 s.  co  m

public class Main{
        public static object GetDefaultInstanceOf(this Type instanceType)
      {
         if (instanceType.IsValueType)
            return Activator.CreateInstance(instanceType, true);
         else
            return null;
      }
}

Related Tutorials