From a9e33bfd2d21f2840f5a5dfc3e278cb383c4b0b9 Mon Sep 17 00:00:00 2001 From: maliming Date: Wed, 4 Nov 2020 16:10:45 +0800 Subject: [PATCH] Remove duplicate TrySetId method. --- .../Volo/Abp/Domain/Entities/EntityHelper.cs | 31 ------------------- .../JsonConverters/EntityJsonConverter.cs | 3 +- 2 files changed, 2 insertions(+), 32 deletions(-) diff --git a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/EntityHelper.cs b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/EntityHelper.cs index b778ec2b67..ecb9252779 100644 --- a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/EntityHelper.cs +++ b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/EntityHelper.cs @@ -266,36 +266,5 @@ namespace Volo.Abp.Domain.Entities property?.SetValue(entity, idFactory()); } - - public static void TrySetId( - object entity, - TKey id, - bool checkForDisableIdGenerationAttribute = false) - { - var property = CachedIdProperties.GetOrAdd( - $"{entity.GetType().FullName}-{checkForDisableIdGenerationAttribute}", () => - { - var idProperty = entity - .GetType() - .GetProperties() - .FirstOrDefault(x => x.Name == nameof(IEntity.Id) && - x.GetSetMethod(true) != null); - - if (idProperty == null) - { - return null; - } - - if (checkForDisableIdGenerationAttribute && - idProperty.IsDefined(typeof(DisableIdGenerationAttribute), true)) - { - return null; - } - - return idProperty; - }); - - property?.SetValue(entity, id); - } } } diff --git a/framework/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/JsonConverters/EntityJsonConverter.cs b/framework/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/JsonConverters/EntityJsonConverter.cs index 8723ce8958..576e7512fa 100644 --- a/framework/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/JsonConverters/EntityJsonConverter.cs +++ b/framework/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/JsonConverters/EntityJsonConverter.cs @@ -6,6 +6,7 @@ using Volo.Abp.Domain.Entities; namespace Volo.Abp.MemoryDb.JsonConverters { public class EntityJsonConverter : JsonConverter + where TEntity : IEntity { public override TEntity Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { @@ -16,7 +17,7 @@ namespace Volo.Abp.MemoryDb.JsonConverters var id = JsonSerializer.Deserialize(idJsonElement.GetRawText()); if (id != null) { - EntityHelper.TrySetId(entity, id); + EntityHelper.TrySetId(entity, () => id); } return entity;