namespace Gs.Toolbox { public static class TypeHelper { public static bool IsPrimitiveExtended(Type type, bool includeNullables = true, bool includeEnums = false) { if (IsPrimitiveExtendedInternal(type, includeEnums)) { return true; } if (includeNullables && IsNullable(type) && type.GenericTypeArguments.Any()) { return IsPrimitiveExtendedInternal(type.GenericTypeArguments[0], includeEnums); } return false; } public static bool IsNullable(Type type) { return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>); } private static bool IsPrimitiveExtendedInternal(Type type, bool includeEnums) { if (type.IsPrimitive) { return true; } if (includeEnums && type.IsEnum) { return true; } return type == typeof(string) || type == typeof(decimal) || type == typeof(DateTime) || type == typeof(DateTimeOffset) || type == typeof(TimeSpan) || type == typeof(Guid); } } }