Browse Source

Refactored TypeHelper

pull/189/head
Halil İbrahim Kalkan 8 years ago
parent
commit
8dab34e68f
  1. 31
      src/Volo.Abp.Core/Volo/Abp/Reflection/TypeHelper.cs

31
src/Volo.Abp.Core/Volo/Abp/Reflection/TypeHelper.cs

@ -3,9 +3,6 @@ using System.Reflection;
namespace Volo.Abp.Reflection namespace Volo.Abp.Reflection
{ {
/// <summary>
/// Some simple type-checking methods used internally.
/// </summary>
public static class TypeHelper public static class TypeHelper
{ {
public static bool IsFunc(object obj) public static bool IsFunc(object obj)
@ -29,39 +26,41 @@ namespace Volo.Abp.Reflection
return obj != null && obj.GetType() == typeof(Func<TReturn>); return obj != null && obj.GetType() == typeof(Func<TReturn>);
} }
public static bool IsPrimitiveExtendedIncludingNullable(Type type, bool includeEnums = false) public static bool IsPrimitiveExtended(Type type, bool includeNullables = true, bool includeEnums = false)
{ {
if (IsPrimitiveExtended(type, includeEnums)) if (IsPrimitiveExtendedInternal(type, includeEnums))
{ {
return true; return true;
} }
if (type.GetTypeInfo().IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>)) if (includeNullables &&
type.IsGenericType &&
type.GetGenericTypeDefinition() == typeof(Nullable<>))
{ {
return IsPrimitiveExtended(type.GenericTypeArguments[0], includeEnums); return IsPrimitiveExtendedInternal(type.GenericTypeArguments[0], includeEnums);
} }
return false; return false;
} }
private static bool IsPrimitiveExtended(Type type, bool includeEnums) private static bool IsPrimitiveExtendedInternal(Type type, bool includeEnums)
{ {
if (type.GetTypeInfo().IsPrimitive) if (type.IsPrimitive)
{ {
return true; return true;
} }
if (includeEnums && type.GetTypeInfo().IsEnum) if (includeEnums && type.IsEnum)
{ {
return true; return true;
} }
return type == typeof (string) || return type == typeof(string) ||
type == typeof (decimal) || type == typeof(decimal) ||
type == typeof (DateTime) || type == typeof(DateTime) ||
type == typeof (DateTimeOffset) || type == typeof(DateTimeOffset) ||
type == typeof (TimeSpan) || type == typeof(TimeSpan) ||
type == typeof (Guid); type == typeof(Guid);
} }
} }
} }

Loading…
Cancel
Save