11using System ;
2+ using System . Globalization ;
23
34namespace SpanExtensions
45{
@@ -22,12 +23,14 @@ public enum CountExceedingBehaviour
2223 /// </summary>
2324 static class CountExceedingBehaviourExtensions
2425 {
26+ static string ? CountExceedingBehaviourInvalidFormat ;
27+
2528 /// <summary>
2629 /// Validates whether a specified value is a valid <see cref="CountExceedingBehaviour"/>.
2730 /// </summary>
2831 /// <param name="countExceedingBehaviour">The <see cref="CountExceedingBehaviour"/> to validate.</param>
2932 /// <returns>The specified <see cref="CountExceedingBehaviour"/> if valid.</returns>
30- /// <exception cref="InvalidCountExceedingBehaviourException ">If <paramref name="countExceedingBehaviour"/> is not valid.</exception>
33+ /// <exception cref="ArgumentException ">If <paramref name="countExceedingBehaviour"/> is not valid.</exception>
3134 public static CountExceedingBehaviour ThrowIfInvalid ( this CountExceedingBehaviour countExceedingBehaviour )
3235 {
3336#if NET5_0_OR_GREATER
@@ -36,7 +39,17 @@ public static CountExceedingBehaviour ThrowIfInvalid(this CountExceedingBehaviou
3639 if ( ! Enum . IsDefined ( typeof ( CountExceedingBehaviour ) , countExceedingBehaviour ) )
3740#endif
3841 {
39- throw new InvalidCountExceedingBehaviourException ( countExceedingBehaviour ) ;
42+ if ( CountExceedingBehaviourInvalidFormat == null )
43+ {
44+ #if NET5_0_OR_GREATER
45+ string [ ] names = Enum . GetNames < CountExceedingBehaviour > ( ) ;
46+ #else
47+ string [ ] names = ( string [ ] ) Enum . GetNames ( typeof ( CountExceedingBehaviour ) ) ;
48+ #endif
49+ CountExceedingBehaviourInvalidFormat = $ "{ nameof ( CountExceedingBehaviour ) } doesn't define an option with the value '{{0}}'. Valid values are { string . Join ( ", " , names ) } .";
50+ }
51+
52+ throw new ArgumentException ( string . Format ( CultureInfo . InvariantCulture , CountExceedingBehaviourInvalidFormat , ( int ) countExceedingBehaviour ) , nameof ( countExceedingBehaviour ) ) ;
4053 }
4154
4255 return countExceedingBehaviour ;
0 commit comments