Skip to content

Commit 017eb02

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

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

DomainModeling/Enums/DefinedEnum.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,14 @@ public static class DefinedEnum
2929
/// </summary>
3030
/// <param name="enumType">The enum's type.</param>
3131
/// <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>
32+
/// <param name="errorState">An optional error state to be passed to <see cref="ExceptionFactoryForUndefinedInput"/>.</param>
33+
/// <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>
3334
[DoesNotReturn]
34-
public static void ThrowUndefinedInput(Type enumType, Int128 numericValue, string? errorState = null)
35+
public static Exception ThrowUndefinedInput(Type enumType, Int128 numericValue, string? errorState = null)
3536
{
3637
throw ExceptionFactoryForUndefinedInput?.Invoke(enumType, numericValue, errorState) ?? new ArgumentException($"Only recognized {enumType.Name} values are permitted.");
37-
}
38-
38+
}
39+
3940
/// <summary>
4041
/// <para>
4142
/// Throws the configured exception for enum value <paramref name="value"/> being undefined for its type.
@@ -45,12 +46,13 @@ public static void ThrowUndefinedInput(Type enumType, Int128 numericValue, strin
4546
/// </para>
4647
/// </summary>
4748
/// <param name="value">The enum's value.</param>
48-
/// <param name="errorState">An optional error state to be passed to <see cref="ExceptionFactoryForUndefinedInput"/>.</param>
49+
/// <param name="errorState">An optional error state to be passed to <see cref="ExceptionFactoryForUndefinedInput"/>.</param>
50+
/// <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>
4951
[DoesNotReturn]
50-
public static void ThrowUndefinedInput<TEnum>(TEnum value, string? errorState = null)
52+
public static TEnum ThrowUndefinedInput<TEnum>(TEnum value, string? errorState = null)
5153
where TEnum : unmanaged, Enum
5254
{
53-
ThrowUndefinedInput(typeof(TEnum), value.GetNumericValue(), errorState);
55+
throw ThrowUndefinedInput(typeof(TEnum), value.GetNumericValue(), errorState);
5456
}
5557

5658
/// <summary>

0 commit comments

Comments
 (0)