diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/Data/HasExtraPropertiesExtensions.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/Data/HasExtraPropertiesExtensions.cs index db543bb67f..2e32a1b7dc 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/Data/HasExtraPropertiesExtensions.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/Data/HasExtraPropertiesExtensions.cs @@ -45,6 +45,11 @@ public static class HasExtraPropertiesExtensions return (TProperty)TypeDescriptor.GetConverter(conversionType).ConvertFromInvariantString(value.ToString()); } + if (conversionType.IsEnum) + { + return (TProperty)value; + } + return (TProperty)Convert.ChangeType(value, conversionType, CultureInfo.InvariantCulture); } @@ -129,7 +134,7 @@ public static class HasExtraPropertiesExtensions { Check.NotNull(source, nameof(source)); Check.NotNull(other, nameof(other)); - + return source.ExtraProperties.HasSameItems(other.ExtraProperties); } } diff --git a/framework/test/Volo.Abp.ObjectExtending.Tests/Volo/Abp/ObjectExtending/AbpObjectExtendingTestModule.cs b/framework/test/Volo.Abp.ObjectExtending.Tests/Volo/Abp/ObjectExtending/AbpObjectExtendingTestModule.cs index 0f8997dfc7..3b99696df4 100644 --- a/framework/test/Volo.Abp.ObjectExtending.Tests/Volo/Abp/ObjectExtending/AbpObjectExtendingTestModule.cs +++ b/framework/test/Volo.Abp.ObjectExtending.Tests/Volo/Abp/ObjectExtending/AbpObjectExtendingTestModule.cs @@ -21,9 +21,11 @@ public class AbpObjectExtendingTestModule : AbpModule .AddOrUpdateProperty("Age") .AddOrUpdateProperty("NoPairCheck", options => options.CheckPairDefinitionOnMapping = false) .AddOrUpdateProperty("CityName") + .AddOrUpdateProperty("EnumProperty") .AddOrUpdateProperty("Name") .AddOrUpdateProperty("ChildCount") .AddOrUpdateProperty("CityName") + .AddOrUpdateProperty("EnumProperty") .AddOrUpdateProperty("Name") .AddOrUpdateProperty("Age"); }); diff --git a/framework/test/Volo.Abp.ObjectExtending.Tests/Volo/Abp/ObjectExtending/ExtensibleObject_Tests.cs b/framework/test/Volo.Abp.ObjectExtending.Tests/Volo/Abp/ObjectExtending/ExtensibleObject_Tests.cs index e5cc39510b..2071609e32 100644 --- a/framework/test/Volo.Abp.ObjectExtending.Tests/Volo/Abp/ObjectExtending/ExtensibleObject_Tests.cs +++ b/framework/test/Volo.Abp.ObjectExtending.Tests/Volo/Abp/ObjectExtending/ExtensibleObject_Tests.cs @@ -16,11 +16,13 @@ public class ExtensibleObject_Tests : AbpObjectExtendingTestBase person.HasProperty("Age").ShouldBeTrue(); person.HasProperty("NoPairCheck").ShouldBeTrue(); person.HasProperty("CityName").ShouldBeTrue(); + person.HasProperty("EnumProperty").ShouldBeTrue(); person.GetProperty("Name").ShouldBeNull(); person.GetProperty("Age").ShouldBe(0); person.GetProperty("NoPairCheck").ShouldBeNull(); person.GetProperty("CityName").ShouldBeNull(); + person.GetProperty("EnumProperty").ShouldBe(default); } [Fact] @@ -32,5 +34,6 @@ public class ExtensibleObject_Tests : AbpObjectExtendingTestBase person.HasProperty("Age").ShouldBeFalse(); person.HasProperty("NoPairCheck").ShouldBeFalse(); person.HasProperty("CityName").ShouldBeFalse(); + person.HasProperty("EnumProperty").ShouldBeFalse(); } } diff --git a/framework/test/Volo.Abp.ObjectExtending.Tests/Volo/Abp/ObjectExtending/HasExtraPropertiesObjectExtendingExtensions_Tests.cs b/framework/test/Volo.Abp.ObjectExtending.Tests/Volo/Abp/ObjectExtending/HasExtraPropertiesObjectExtendingExtensions_Tests.cs index 5bf34515ef..e9f3de2784 100644 --- a/framework/test/Volo.Abp.ObjectExtending.Tests/Volo/Abp/ObjectExtending/HasExtraPropertiesObjectExtendingExtensions_Tests.cs +++ b/framework/test/Volo.Abp.ObjectExtending.Tests/Volo/Abp/ObjectExtending/HasExtraPropertiesObjectExtendingExtensions_Tests.cs @@ -18,7 +18,8 @@ public class HasExtraPropertiesObjectExtendingExtensions_Tests : AbpObjectExtend .SetProperty("ChildCount", 2) .SetProperty("Sex", "male") .SetProperty("NoPairCheck", "test-value") - .SetProperty("CityName", "Adana"); + .SetProperty("CityName", "Adana") + .SetProperty("EnumProperty", (int)ExtensibleTestEnumProperty.Value1); _personDto = new ExtensibleTestPersonDto() .SetProperty("ExistingDtoProperty", "existing-value"); @@ -31,6 +32,7 @@ public class HasExtraPropertiesObjectExtendingExtensions_Tests : AbpObjectExtend _personDto.GetProperty("Name").ShouldBe("John"); //Defined in both classes _personDto.GetProperty("CityName").ShouldBe("Adana"); //Defined in both classes + _personDto.GetProperty("EnumProperty").ShouldBe(ExtensibleTestEnumProperty.Value1); //Defined in both classes _personDto.GetProperty("NoPairCheck").ShouldBe("test-value"); //CheckPairDefinitionOnMapping = false _personDto.GetProperty("ExistingDtoProperty").ShouldBe("existing-value"); //Should not clear existing values _personDto.HasProperty("Age").ShouldBeFalse(); //Not defined on the destination @@ -44,6 +46,7 @@ public class HasExtraPropertiesObjectExtendingExtensions_Tests : AbpObjectExtend _person.MapExtraPropertiesTo(_personDto, ignoredProperties: new[] { "CityName" }); _personDto.GetProperty("Name").ShouldBe("John"); //Defined in both classes + _personDto.GetProperty("EnumProperty").ShouldBe(ExtensibleTestEnumProperty.Value1); //Defined in both classes _personDto.GetProperty("NoPairCheck").ShouldBe("test-value"); //CheckPairDefinitionOnMapping = false _personDto.GetProperty("ExistingDtoProperty").ShouldBe("existing-value"); //Should not clear existing values _personDto.GetProperty("CityName").ShouldBeNull(); //Ignored, but was set to the default in the constructor @@ -59,6 +62,7 @@ public class HasExtraPropertiesObjectExtendingExtensions_Tests : AbpObjectExtend _personDto.GetProperty("Name").ShouldBe("John"); //Defined in both classes _personDto.GetProperty("CityName").ShouldBe("Adana"); //Defined in both classes + _personDto.GetProperty("EnumProperty").ShouldBe(ExtensibleTestEnumProperty.Value1); //Defined in both classes _personDto.GetProperty("Age").ShouldBe(42); //Defined in source _personDto.GetProperty("ExistingDtoProperty").ShouldBe("existing-value"); //Should not clear existing values _personDto.GetProperty("ChildCount").ShouldBe(0); //Not defined in the source, but was set to the default in the constructor @@ -72,6 +76,7 @@ public class HasExtraPropertiesObjectExtendingExtensions_Tests : AbpObjectExtend _personDto.GetProperty("Name").ShouldBe("John"); //Defined in both classes _personDto.GetProperty("CityName").ShouldBe("Adana"); //Defined in both classes + _personDto.GetProperty("EnumProperty").ShouldBe(ExtensibleTestEnumProperty.Value1); //Defined in both classes _personDto.GetProperty("ChildCount").ShouldBe(2); //Defined in destination _personDto.GetProperty("ExistingDtoProperty").ShouldBe("existing-value"); //Should not clear existing values _personDto.HasProperty("Age").ShouldBeFalse(); //Not defined in destination @@ -88,6 +93,7 @@ public class HasExtraPropertiesObjectExtendingExtensions_Tests : AbpObjectExtend _personDto.GetProperty("Age").ShouldBe(42); _personDto.GetProperty("ChildCount").ShouldBe(2); _personDto.GetProperty("Sex").ShouldBe("male"); + _personDto.GetProperty("EnumProperty").ShouldBe(ExtensibleTestEnumProperty.Value1); _personDto.GetProperty("ExistingDtoProperty").ShouldBe("existing-value"); //Should not clear existing values } } diff --git a/framework/test/Volo.Abp.ObjectExtending.Tests/Volo/Abp/ObjectExtending/TestObjects/ExtensibleTestPerson.cs b/framework/test/Volo.Abp.ObjectExtending.Tests/Volo/Abp/ObjectExtending/TestObjects/ExtensibleTestPerson.cs index 8fb8380d44..81a08ec227 100644 --- a/framework/test/Volo.Abp.ObjectExtending.Tests/Volo/Abp/ObjectExtending/TestObjects/ExtensibleTestPerson.cs +++ b/framework/test/Volo.Abp.ObjectExtending.Tests/Volo/Abp/ObjectExtending/TestObjects/ExtensibleTestPerson.cs @@ -13,3 +13,9 @@ public class ExtensibleTestPerson : ExtensibleObject } } + +public enum ExtensibleTestEnumProperty +{ + Value1, + Value2 +}