Is User Defined Type - CSharp System.Reflection

CSharp examples for System.Reflection:Type

Description

Is User Defined Type

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;/*w w  w .ja  v  a 2  s.  co  m*/
using System.Globalization;
using System.Collections.Generic;
using System;

public class Main{
        public static bool IsUserDefinedType(this Type type)
        {
            return !type.IsListType() && !type.IsDictionaryType() && !type.IsEnum() && !type.IsPrimitiveType();
        }
        public static bool IsPrimitiveType(this Type t)
        {
            return
                t == typeof(string) ||
                t == typeof(char) ||
                t == typeof(float) ||
                t == typeof(double) ||
                t == typeof(decimal) ||
                t == typeof(byte) ||
                t == typeof(sbyte) ||
                t == typeof(short) ||
                t == typeof(ushort) ||
                t == typeof(int) ||
                t == typeof(uint) ||
                t == typeof(long) ||
                t == typeof(ulong) ||
                t == typeof(bool) ||
                t == typeof(DateTime) ||
                t == typeof(DateTimeOffset) ||
                t == typeof(Guid) ||
                t == typeof(TimeSpan);
        }
        public static bool IsEnum(this Type type)
        {
            var info = type.GetTypeInfo();

            return info.IsEnum;
        }
        public static bool IsListType(this Type t)
        {
            return t.IsContainerType(typeof(IList<>));
        }
        public static bool IsDictionaryType(this Type t)
        {
            return t.IsContainerType(typeof(IDictionary<,>));
        }
}

Related Tutorials