C# Test for Basic Type

Below a basic C# function to test to see if a type is a basic type

C# Basic Data Types

The function below basically tests to see if type object is a type that a basic type or core type of C#. This can be used in functions that automatically fill objects. Alternatively in a function like NotAComplexType.

All objects have some properties, this saves the compiler form running through basic types or allows you to test if the current property is a custom class vs a basic object.

public static bool IsBasicType(object obj)
{
    Type objType = obj.GetType();
    if (objType == typeof(bool)
        || objType == typeof(byte)
        || objType == typeof(char)
        || objType == typeof(DateTime)
        || objType == typeof(decimal)
        || objType == typeof(double)
        || objType == typeof(float)
        || objType == typeof(int)
        || objType == typeof(long)
        || objType == typeof(sbyte)
        || objType == typeof(short)
        || objType == typeof(string)
        || objType == typeof(uint)
        || objType == typeof(ulong)
        || objType == typeof(ushort)
    )
    {
        return true;
    }
    return false;
}