From d12186799b84ec021f9604f4f25b1a1382dc8834 Mon Sep 17 00:00:00 2001 From: Jan Trejbal Date: Tue, 22 Aug 2023 12:34:34 +0200 Subject: [PATCH] fix: add AllowMultiple into MapEnumValueAttribute --- src/Riok.Mapperly.Abstractions/MapEnumValueAttribute.cs | 2 +- .../Dto/TestEnumDtoAdditionalValue.cs | 1 + .../Riok.Mapperly.IntegrationTests/Mapper/StaticTestMapper.cs | 2 ++ .../StaticMapperTest.SnapshotGeneratedSource.verified.cs | 2 ++ .../StaticMapperTest.SnapshotGeneratedSource.verified.cs | 2 ++ .../StaticMapperTest.SnapshotGeneratedSource.verified.cs | 4 +++- 6 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Riok.Mapperly.Abstractions/MapEnumValueAttribute.cs b/src/Riok.Mapperly.Abstractions/MapEnumValueAttribute.cs index 75fcc55457..64c168fa94 100644 --- a/src/Riok.Mapperly.Abstractions/MapEnumValueAttribute.cs +++ b/src/Riok.Mapperly.Abstractions/MapEnumValueAttribute.cs @@ -3,7 +3,7 @@ namespace Riok.Mapperly.Abstractions; /// /// Customizes how enum values are mapped /// -[AttributeUsage(AttributeTargets.Method)] +[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] public sealed class MapEnumValueAttribute : Attribute { /// diff --git a/test/Riok.Mapperly.IntegrationTests/Dto/TestEnumDtoAdditionalValue.cs b/test/Riok.Mapperly.IntegrationTests/Dto/TestEnumDtoAdditionalValue.cs index 51123e2915..af0be0195d 100644 --- a/test/Riok.Mapperly.IntegrationTests/Dto/TestEnumDtoAdditionalValue.cs +++ b/test/Riok.Mapperly.IntegrationTests/Dto/TestEnumDtoAdditionalValue.cs @@ -6,5 +6,6 @@ public enum TestEnumDtoAdditionalValue Value20 = 20, Value30 = 30, Value40 = 40, + Value50 = 50, } } diff --git a/test/Riok.Mapperly.IntegrationTests/Mapper/StaticTestMapper.cs b/test/Riok.Mapperly.IntegrationTests/Mapper/StaticTestMapper.cs index 3af649863d..1f1c71ec7a 100644 --- a/test/Riok.Mapperly.IntegrationTests/Mapper/StaticTestMapper.cs +++ b/test/Riok.Mapperly.IntegrationTests/Mapper/StaticTestMapper.cs @@ -95,10 +95,12 @@ public static void MapExistingList(List src, List dst) [MapEnum(EnumMappingStrategy.ByName)] [MapEnumValue(TestEnumDtoAdditionalValue.Value40, TestEnum.Value30)] + [MapEnumValue(TestEnumDtoAdditionalValue.Value50, TestEnum.Value30)] public static partial TestEnum MapToEnumByNameWithExplicit(TestEnumDtoAdditionalValue v); [MapEnum(EnumMappingStrategy.ByValue)] [MapEnumValue(TestEnumDtoAdditionalValue.Value40, TestEnum.Value30)] + [MapEnumValue(TestEnumDtoAdditionalValue.Value50, TestEnum.Value30)] public static partial TestEnum MapToEnumByValueWithExplicit(TestEnumDtoAdditionalValue v); [MapEnum(EnumMappingStrategy.ByName)] diff --git a/test/Riok.Mapperly.IntegrationTests/_snapshots/NET_48/StaticMapperTest.SnapshotGeneratedSource.verified.cs b/test/Riok.Mapperly.IntegrationTests/_snapshots/NET_48/StaticMapperTest.SnapshotGeneratedSource.verified.cs index a8eac642be..e48f611e0d 100644 --- a/test/Riok.Mapperly.IntegrationTests/_snapshots/NET_48/StaticMapperTest.SnapshotGeneratedSource.verified.cs +++ b/test/Riok.Mapperly.IntegrationTests/_snapshots/NET_48/StaticMapperTest.SnapshotGeneratedSource.verified.cs @@ -527,6 +527,7 @@ object x when typeof(TTarget).IsAssignableFrom(typeof(object)) => (TTarget)(obje global::Riok.Mapperly.IntegrationTests.Dto.TestEnumDtoAdditionalValue.Value20 => global::Riok.Mapperly.IntegrationTests.Models.TestEnum.Value20, global::Riok.Mapperly.IntegrationTests.Dto.TestEnumDtoAdditionalValue.Value30 => global::Riok.Mapperly.IntegrationTests.Models.TestEnum.Value30, global::Riok.Mapperly.IntegrationTests.Dto.TestEnumDtoAdditionalValue.Value40 => global::Riok.Mapperly.IntegrationTests.Models.TestEnum.Value30, + global::Riok.Mapperly.IntegrationTests.Dto.TestEnumDtoAdditionalValue.Value50 => global::Riok.Mapperly.IntegrationTests.Models.TestEnum.Value30, _ => throw new System.ArgumentOutOfRangeException(nameof(v), v, "The value of enum TestEnumDtoAdditionalValue is not supported"), }; } @@ -536,6 +537,7 @@ object x when typeof(TTarget).IsAssignableFrom(typeof(object)) => (TTarget)(obje return v switch { global::Riok.Mapperly.IntegrationTests.Dto.TestEnumDtoAdditionalValue.Value40 => global::Riok.Mapperly.IntegrationTests.Models.TestEnum.Value30, + global::Riok.Mapperly.IntegrationTests.Dto.TestEnumDtoAdditionalValue.Value50 => global::Riok.Mapperly.IntegrationTests.Models.TestEnum.Value30, _ => (global::Riok.Mapperly.IntegrationTests.Models.TestEnum)v, }; } diff --git a/test/Riok.Mapperly.IntegrationTests/_snapshots/Roslyn_4_4_OR_LOWER/StaticMapperTest.SnapshotGeneratedSource.verified.cs b/test/Riok.Mapperly.IntegrationTests/_snapshots/Roslyn_4_4_OR_LOWER/StaticMapperTest.SnapshotGeneratedSource.verified.cs index bc12d07b41..48c144ef06 100644 --- a/test/Riok.Mapperly.IntegrationTests/_snapshots/Roslyn_4_4_OR_LOWER/StaticMapperTest.SnapshotGeneratedSource.verified.cs +++ b/test/Riok.Mapperly.IntegrationTests/_snapshots/Roslyn_4_4_OR_LOWER/StaticMapperTest.SnapshotGeneratedSource.verified.cs @@ -527,6 +527,7 @@ object x when typeof(TTarget).IsAssignableFrom(typeof(object)) => (TTarget)(obje global::Riok.Mapperly.IntegrationTests.Dto.TestEnumDtoAdditionalValue.Value20 => global::Riok.Mapperly.IntegrationTests.Models.TestEnum.Value20, global::Riok.Mapperly.IntegrationTests.Dto.TestEnumDtoAdditionalValue.Value30 => global::Riok.Mapperly.IntegrationTests.Models.TestEnum.Value30, global::Riok.Mapperly.IntegrationTests.Dto.TestEnumDtoAdditionalValue.Value40 => global::Riok.Mapperly.IntegrationTests.Models.TestEnum.Value30, + global::Riok.Mapperly.IntegrationTests.Dto.TestEnumDtoAdditionalValue.Value50 => global::Riok.Mapperly.IntegrationTests.Models.TestEnum.Value30, _ => throw new System.ArgumentOutOfRangeException(nameof(v), v, "The value of enum TestEnumDtoAdditionalValue is not supported"), }; } @@ -536,6 +537,7 @@ object x when typeof(TTarget).IsAssignableFrom(typeof(object)) => (TTarget)(obje return v switch { global::Riok.Mapperly.IntegrationTests.Dto.TestEnumDtoAdditionalValue.Value40 => global::Riok.Mapperly.IntegrationTests.Models.TestEnum.Value30, + global::Riok.Mapperly.IntegrationTests.Dto.TestEnumDtoAdditionalValue.Value50 => global::Riok.Mapperly.IntegrationTests.Models.TestEnum.Value30, _ => (global::Riok.Mapperly.IntegrationTests.Models.TestEnum)v, }; } diff --git a/test/Riok.Mapperly.IntegrationTests/_snapshots/Roslyn_4_5/StaticMapperTest.SnapshotGeneratedSource.verified.cs b/test/Riok.Mapperly.IntegrationTests/_snapshots/Roslyn_4_5/StaticMapperTest.SnapshotGeneratedSource.verified.cs index f7bac3307e..3c64e3b8f2 100644 --- a/test/Riok.Mapperly.IntegrationTests/_snapshots/Roslyn_4_5/StaticMapperTest.SnapshotGeneratedSource.verified.cs +++ b/test/Riok.Mapperly.IntegrationTests/_snapshots/Roslyn_4_5/StaticMapperTest.SnapshotGeneratedSource.verified.cs @@ -536,6 +536,7 @@ object x when typeof(TTarget).IsAssignableFrom(typeof(object)) => (TTarget)(obje global::Riok.Mapperly.IntegrationTests.Dto.TestEnumDtoAdditionalValue.Value20 => global::Riok.Mapperly.IntegrationTests.Models.TestEnum.Value20, global::Riok.Mapperly.IntegrationTests.Dto.TestEnumDtoAdditionalValue.Value30 => global::Riok.Mapperly.IntegrationTests.Models.TestEnum.Value30, global::Riok.Mapperly.IntegrationTests.Dto.TestEnumDtoAdditionalValue.Value40 => global::Riok.Mapperly.IntegrationTests.Models.TestEnum.Value30, + global::Riok.Mapperly.IntegrationTests.Dto.TestEnumDtoAdditionalValue.Value50 => global::Riok.Mapperly.IntegrationTests.Models.TestEnum.Value30, _ => throw new System.ArgumentOutOfRangeException(nameof(v), v, "The value of enum TestEnumDtoAdditionalValue is not supported"), }; } @@ -545,6 +546,7 @@ object x when typeof(TTarget).IsAssignableFrom(typeof(object)) => (TTarget)(obje return v switch { global::Riok.Mapperly.IntegrationTests.Dto.TestEnumDtoAdditionalValue.Value40 => global::Riok.Mapperly.IntegrationTests.Models.TestEnum.Value30, + global::Riok.Mapperly.IntegrationTests.Dto.TestEnumDtoAdditionalValue.Value50 => global::Riok.Mapperly.IntegrationTests.Models.TestEnum.Value30, _ => (global::Riok.Mapperly.IntegrationTests.Models.TestEnum)v, }; } @@ -728,4 +730,4 @@ private static string MapToString1(global::Riok.Mapperly.IntegrationTests.Dto.Te return target; } } -} \ No newline at end of file +}