33
44using System ;
55using System . ComponentModel ;
6+ using System . Diagnostics ;
67using System . Diagnostics . CodeAnalysis ;
78using System . Runtime . CompilerServices ;
89
@@ -16,14 +17,18 @@ namespace Ubiquity.NET.Extensions
1617 /// They also serve to provide validation when using body expressions for property
1718 /// method implementations etc...
1819 /// </remarks>
19- public static class ValidationExtensions
20+ public static class FluentValidationExtensions
2021 {
22+ // NOTE: These DO NOT use the new `extension` keyword syntax as it is not clear
23+ // how CallerArgumentExpression is supposed to be used for those...
24+
2125 /// <summary>Throws an exception if <paramref name="obj"/> is <see langword="null"/></summary>
2226 /// <typeparam name="T">Type of reference parameter to test for</typeparam>
2327 /// <param name="obj">Instance to test</param>
2428 /// <param name="exp">Name or expression of the value in <paramref name="obj"/> [Default: provided by compiler]</param>
2529 /// <returns><paramref name="obj"/></returns>
2630 /// <exception cref="ArgumentNullException"><paramref name="obj"/> is <see langword="null"/></exception>
31+ [ DebuggerStepThrough ]
2732 public static T ThrowIfNull < T > ( [ NotNull ] this T ? obj , [ CallerArgumentExpression ( nameof ( obj ) ) ] string ? exp = null )
2833 {
2934 ArgumentNullException . ThrowIfNull ( obj , exp ) ;
@@ -38,9 +43,11 @@ public static T ThrowIfNull<T>( [NotNull] this T? obj, [CallerArgumentExpression
3843 /// <param name="max">Maximum value allowed for <paramref name="self"/></param>
3944 /// <param name="exp">Name or expression of the value in <paramref name="self"/> [Default: provided by compiler]</param>
4045 /// <returns><paramref name="self"/></returns>
46+ [ DebuggerStepThrough ]
4147 public static T ThrowIfOutOfRange < T > ( this T self , T min , T max , [ CallerArgumentExpression ( nameof ( self ) ) ] string ? exp = null )
4248 where T : struct , IComparable < T >
4349 {
50+ ArgumentNullException . ThrowIfNull ( self , exp ) ;
4451 ArgumentOutOfRangeException . ThrowIfLessThan ( self , min , exp ) ;
4552 ArgumentOutOfRangeException . ThrowIfGreaterThan ( self , max , exp ) ;
4653
@@ -59,10 +66,12 @@ public static T ThrowIfOutOfRange<T>( this T self, T min, T max, [CallerArgument
5966 /// <see cref="FlagsAttribute"/> as a legit value that is a combination of flags does not have
6067 /// a defined value (Only single bit values do)
6168 /// </remarks>
69+ [ DebuggerStepThrough ]
6270 public static T ThrowIfNotDefined < T > ( this T self , [ CallerArgumentExpression ( nameof ( self ) ) ] string ? exp = null )
6371 where T : struct , Enum
6472 {
65- return Enum . IsDefined < T > ( self ) ? self : throw new InvalidEnumArgumentException ( exp ) ;
73+ ArgumentNullException . ThrowIfNull ( self , exp ) ;
74+ return Enum . IsDefined ( typeof ( T ) , self ) ? self : throw new InvalidEnumArgumentException ( exp ) ;
6675 }
6776 }
6877}
0 commit comments