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

Loading…
Cancel
Save