Browse Source

Added GetFirstGenericArgumentIfNullable extension method

pull/395/head
Yunus Emre Kalkan 8 years ago
parent
commit
1bbaefa34b
  1. 15
      framework/src/Volo.Abp.Core/Volo/Abp/Reflection/TypeHelper.cs
  2. 5
      framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/EntityHistory/EntityHistoryHelper.cs

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

@ -1,4 +1,5 @@
using System;
using System.Linq;
using System.Reflection;
namespace Volo.Abp.Reflection
@ -33,8 +34,8 @@ namespace Volo.Abp.Reflection
return true;
}
if (includeNullables &&
type.IsGenericType &&
if (includeNullables &&
type.IsGenericType &&
type.GetGenericTypeDefinition() == typeof(Nullable<>))
{
return IsPrimitiveExtendedInternal(type.GenericTypeArguments[0], includeEnums);
@ -43,6 +44,16 @@ namespace Volo.Abp.Reflection
return false;
}
public static Type GetFirstGenericArgumentIfNullable(this Type t)
{
if (t.GetGenericArguments().Length > 0 && t.GetGenericTypeDefinition() == typeof(Nullable<>))
{
return t.GetGenericArguments().FirstOrDefault();
}
return t;
}
private static bool IsPrimitiveExtendedInternal(Type type, bool includeEnums)
{
if (type.IsPrimitive)

5
framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/EntityHistory/EntityHistoryHelper.cs

@ -13,6 +13,7 @@ using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Json;
using Volo.Abp.MultiTenancy;
using Volo.Abp.Reflection;
using Volo.Abp.Timing;
using Volo.Abp.Uow;
@ -170,7 +171,7 @@ namespace Volo.Abp.EntityFrameworkCore.EntityHistory
NewValue = isDeleted ? null : JsonSerializer.Serialize(propertyEntry.CurrentValue).TruncateWithPostfix(EntityPropertyChangeInfo.MaxValueLength),
OriginalValue = isCreated ? null : JsonSerializer.Serialize(propertyEntry.OriginalValue).TruncateWithPostfix(EntityPropertyChangeInfo.MaxValueLength),
PropertyName = property.Name,
PropertyTypeFullName = property.ClrType.FullName,
PropertyTypeFullName = property.ClrType.GetFirstGenericArgumentIfNullable().FullName,
TenantId = GetTenantId(entityEntry.Entity)
});
}
@ -311,7 +312,7 @@ namespace Volo.Abp.EntityFrameworkCore.EntityHistory
NewValue = JsonSerializer.Serialize(propertyEntry.CurrentValue),
OriginalValue = JsonSerializer.Serialize(propertyEntry.OriginalValue),
PropertyName = property.Name,
PropertyTypeFullName = property.ClrType.FullName
PropertyTypeFullName = property.ClrType.GetFirstGenericArgumentIfNullable().FullName
});
}

Loading…
Cancel
Save