Skip to content

Commit 1429346

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

2 files changed

Lines changed: 16 additions & 14 deletions

File tree

DomainModeling/DomainModeling.csproj

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Platforms:
4040
The base class is dead - long live the interface!
4141
- Feature: Generated [Wrapper]ValueObjects can now be structs. Unvalidated instances avoided via analyzer warning on `default`.
4242
- Feature: Generated [Wrapper]ValueObjects can now be records or use custom base.
43-
- BREAKING: [Wrapper]ValueObject generator replaced base class by interface. StringComparison property should drop "override" and become private.
43+
- BREAKING: [Wrapper]ValueObject gen replaced base class by interface. StringComparison property should drop "override" and become private.
4444
- BREAKING: Lack of ValueObject base class requires the string validation methods to be accessed via ValueObjectStringValidator class.
4545
- BREAKING: Entity<TId, TPrimitive> type params moved from base class to attribute.
4646

@@ -67,18 +67,18 @@ Misc:
6767
- Semi-breaking: Entity<TId> now has ID-based ==/!=.
6868
- Semi-breaking: IFormattable & co for string wrappers have stopped treating null strings as "", to better reveal mistakes.
6969
- Semi-breaking: IIdentity implements IWrapperValueObject.
70-
- Semi-breaking: Wrappers/Identities generate no parameterized ctor if ANY parameterized exists.
70+
- Semi-breaking: Wrappers/Identities generate no parameterized ctor if ANY ctor has params.
7171
- Feature: Analyzer and extensions for defined enums.
7272
- Feature: Non-generic Wrapper/Identity interfaces.
73-
- Feature: DummyBuilder records cloned on each step, for reuse.
74-
- Feature: Analyzer warns when '==' or similar operator implicitly casts some IValueObject to something else. Avoids accidentally comparing unrelated types.
73+
- Feature: DummyBuilder RECORDS cloned on each step, for reuse.
74+
- Feature: Analyzer warns when '==' or similar implicitly casts some IValueObject to something else, to Avoid incorrect comparison.
7575
- Feature: Analyzer warns when '>' or similar operator risks unintended null handling.
7676
- Feature: Analyzer warns if field initializers might be skipped.
7777
- Fixed: Source-generated default ctor should not exist in case of primary ctor or lacking base default ctor.
7878
- Fixed: Source-generated records would ignore hand-written ToString()/Equals()/GetHashCode().
79-
- Fixed: Source-generated Wrappers/Identities would not recognize manual explicit interface implementations.
80-
- Fixed: DummyBuilder generator would struggle with nested types.
81-
- Fixed: "No source generation on nested type" warning would not show.
79+
- Fixed: Source-generated Wrappers/Identities would ignore hand-written explicit interface implementations.
80+
- Fixed: DummyBuilder gen would struggle with nested types.
81+
- Fixed: "No source gen on nested type" warning would not show.
8282
- Fixed: Custom attribute inheritance.
8383
- Enhancement: CompilerGeneratedAttribute throughout.
8484
- Enhancement: DebuggerDisplay for Wrappers/Identities.

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)