Forked from jonathanconway/TypeExtensions.IsSimpleType.cs
Created
August 2, 2016 08:28
-
-
Save truseed/ae2815965c15c0f1392c6fec055b9db0 to your computer and use it in GitHub Desktop.
Determine whether a type is simple.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class TypeExtensions | |
{ | |
/// <summary> | |
/// Determine whether a type is simple (String, Decimal, DateTime, etc) | |
/// or complex (i.e. custom class with public properties and methods). | |
/// </summary> | |
/// <see cref="http://stackoverflow.com/questions/2442534/how-to-test-if-type-is-primitive"/> | |
public static bool IsSimpleType( | |
this Type type) | |
{ | |
return | |
type.IsValueType || | |
type.IsPrimitive || | |
new Type[] { | |
typeof(String), | |
typeof(Decimal), | |
typeof(DateTime), | |
typeof(DateTimeOffset), | |
typeof(TimeSpan), | |
typeof(Guid) | |
}.Contains(type) || | |
Convert.GetTypeCode(type) != TypeCode.Object; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment