Is Simple Type - CSharp System.Reflection

CSharp examples for System.Reflection:Type

Description

Is Simple Type

Demo Code


using System.Reflection;
using System.Linq;
using System.Collections.Generic;
using System;//from  w  w  w.j  a  va2  s  .c om

public class Main{
        public static bool IsSimpleType(this Type type)
        {
            if (type.IsGenericType && (type.GetGenericTypeDefinition() == typeof(Nullable<>) ||
                                       type.GetGenericTypeDefinition() == typeof(List<>) ||
                                       type.GetGenericTypeDefinition() == typeof(IEnumerable<>)))
            {
                type = type.GetGenericArguments()[0];
            }


            return type.IsPrimitive
                   || type.IsEnum
                   || type == typeof(string)
                   || type == typeof(DateTime)
                   || type == typeof(Version)
                   || type == typeof(decimal);
        }
}

Related Tutorials