Skip to content

Commit

Permalink
fix: Allow multiple MapEnumValueAttribute (#672)
Browse files Browse the repository at this point in the history
  • Loading branch information
trejjam authored Aug 23, 2023
1 parent a5f6aef commit 71cbfdd
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Riok.Mapperly.Abstractions/MapEnumValueAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace Riok.Mapperly.Abstractions;
/// <summary>
/// Customizes how enum values are mapped
/// </summary>
[AttributeUsage(AttributeTargets.Method)]
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
public sealed class MapEnumValueAttribute : Attribute
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ public enum TestEnumDtoAdditionalValue
Value20 = 20,
Value30 = 30,
Value40 = 40,
Value50 = 50,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,12 @@ public static void MapExistingList(List<string> src, List<int> 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)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
};
}
Expand All @@ -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,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
};
}
Expand All @@ -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,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
};
}
Expand All @@ -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,
};
}
Expand Down Expand Up @@ -728,4 +730,4 @@ private static string MapToString1(global::Riok.Mapperly.IntegrationTests.Dto.Te
return target;
}
}
}
}

0 comments on commit 71cbfdd

Please sign in to comment.