Browse Source

Extract TypeHelper.IsNullable.

pull/3475/head
Halil İbrahim Kalkan 6 years ago
parent
commit
34128a63aa
  1. 12
      framework/src/Volo.Abp.Core/Volo/Abp/Reflection/TypeHelper.cs

12
framework/src/Volo.Abp.Core/Volo/Abp/Reflection/TypeHelper.cs

@ -1,7 +1,6 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
@ -15,7 +14,7 @@ namespace Volo.Abp.Reflection
{ {
return false; return false;
} }
var type = obj.GetType(); var type = obj.GetType();
if (!type.GetTypeInfo().IsGenericType) if (!type.GetTypeInfo().IsGenericType)
{ {
@ -37,9 +36,7 @@ namespace Volo.Abp.Reflection
return true; return true;
} }
if (includeNullables && if (includeNullables && IsNullable(type))
type.IsGenericType &&
type.GetGenericTypeDefinition() == typeof(Nullable<>))
{ {
return IsPrimitiveExtendedInternal(type.GenericTypeArguments[0], includeEnums); return IsPrimitiveExtendedInternal(type.GenericTypeArguments[0], includeEnums);
} }
@ -47,6 +44,11 @@ namespace Volo.Abp.Reflection
return false; return false;
} }
public static bool IsNullable(Type type)
{
return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>);
}
public static Type GetFirstGenericArgumentIfNullable(this Type t) public static Type GetFirstGenericArgumentIfNullable(this Type t)
{ {
if (t.GetGenericArguments().Length > 0 && t.GetGenericTypeDefinition() == typeof(Nullable<>)) if (t.GetGenericArguments().Length > 0 && t.GetGenericTypeDefinition() == typeof(Nullable<>))

Loading…
Cancel
Save