Default Value - CSharp System.Reflection

CSharp examples for System.Reflection:Type

Description

Default Value

Demo Code


using System.Threading.Tasks;
using System.Text;
using System.Runtime.Serialization;
using System.Runtime.CompilerServices;
using System.Reflection.Emit;
using System.Reflection;
using System.Linq;
using System.IO;/*from  w w w  .  j  a v a 2  s. c o m*/
using System.Globalization;
using System.Collections.Generic;
using System;

public class Main{
        public static object DefaultValue(this Type t)
        {
            if (!t.IsValueType()) return null;

            return Activator.CreateInstance(t);
        }
        public static bool IsValueType(this Type type)
        {
            var info = type.GetTypeInfo();

            return info.IsValueType;
        }
}

Related Tutorials