Skip to content

Commit 7a1ec46

Browse files
committed
DefinedEnum.ThrowUndefinedInput() now has return type, to facilitate use in expressions.
1 parent c04d570 commit 7a1ec46

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

DomainModeling/Enums/DefinedEnum.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Diagnostics;
12
using System.Diagnostics.CodeAnalysis;
23
using Architect.DomainModeling.Enums;
34

@@ -29,13 +30,14 @@ public static class DefinedEnum
2930
/// </summary>
3031
/// <param name="enumType">The enum's type.</param>
3132
/// <param name="numericValue">The enum's numeric value, such as (Int128)(int)HttpStatusCode.OK.</param>
32-
/// <param name="errorState">An optional error state to be passed to <see cref="ExceptionFactoryForUndefinedInput"/>.</param>
33+
/// <param name="errorState">An optional error state to be passed to <see cref="ExceptionFactoryForUndefinedInput"/>.</param>
34+
/// <returns>Pretends to return an <see cref="Exception"/>, to facilitate use in expressions (e.g. switch expression), where a result or a throw is required.</returns>
3335
[DoesNotReturn]
34-
public static void ThrowUndefinedInput(Type enumType, Int128 numericValue, string? errorState = null)
36+
public static Exception ThrowUndefinedInput(Type enumType, Int128 numericValue, string? errorState = null)
3537
{
3638
throw ExceptionFactoryForUndefinedInput?.Invoke(enumType, numericValue, errorState) ?? new ArgumentException($"Only recognized {enumType.Name} values are permitted.");
37-
}
38-
39+
}
40+
3941
/// <summary>
4042
/// <para>
4143
/// Throws the configured exception for enum value <paramref name="value"/> being undefined for its type.
@@ -45,12 +47,13 @@ public static void ThrowUndefinedInput(Type enumType, Int128 numericValue, strin
4547
/// </para>
4648
/// </summary>
4749
/// <param name="value">The enum's value.</param>
48-
/// <param name="errorState">An optional error state to be passed to <see cref="ExceptionFactoryForUndefinedInput"/>.</param>
50+
/// <param name="errorState">An optional error state to be passed to <see cref="ExceptionFactoryForUndefinedInput"/>.</param>
51+
/// <returns>Pretends to return <typeparamref name="TEnum"/>, to facilitate use in expressions (e.g. switch expression), where a result or a throw is required.</returns>
4952
[DoesNotReturn]
50-
public static void ThrowUndefinedInput<TEnum>(TEnum value, string? errorState = null)
53+
public static TEnum ThrowUndefinedInput<TEnum>(TEnum value, string? errorState = null)
5154
where TEnum : unmanaged, Enum
5255
{
53-
ThrowUndefinedInput(typeof(TEnum), value.GetNumericValue(), errorState);
56+
throw ThrowUndefinedInput(typeof(TEnum), value.GetNumericValue(), errorState);
5457
}
5558

5659
/// <summary>

0 commit comments

Comments
 (0)