33/// <summary>
44/// Defines extensions for configuring <see cref="PolicyWrap"/> instances on an <see cref="IAsyncPolicy"/> or <see cref="IAsyncPolicy{TResult}"/>.
55/// </summary>
6- #pragma warning disable CA1062 // Validate arguments of public methods
76public static class IAsyncPolicyPolicyWrapExtensions
87{
98 /// <summary>
@@ -159,13 +158,20 @@ public partial class Policy
159158 /// <param name="policies">The policies to place in the wrap, outermost (at left) to innermost (at right).</param>
160159 /// <returns>The PolicyWrap.</returns>
161160 /// <exception cref="ArgumentException">The enumerable of policies to form the wrap must contain at least two policies.</exception>
162- public static AsyncPolicyWrap WrapAsync ( params IAsyncPolicy [ ] policies ) =>
163- policies . Length switch
161+ public static AsyncPolicyWrap WrapAsync ( params IAsyncPolicy [ ] policies )
162+ {
163+ if ( policies is null )
164+ {
165+ throw new ArgumentNullException ( nameof ( policies ) ) ;
166+ }
167+
168+ return policies . Length switch
164169 {
165170 < MinimumPoliciesRequiredForWrap => throw new ArgumentException ( "The enumerable of policies to form the wrap must contain at least two policies." , nameof ( policies ) ) ,
166171 MinimumPoliciesRequiredForWrap => new AsyncPolicyWrap ( ( AsyncPolicy ) policies [ 0 ] , policies [ 1 ] ) ,
167172 _ => WrapAsync ( policies [ 0 ] , WrapAsync ( policies . Skip ( 1 ) . ToArray ( ) ) ) ,
168173 } ;
174+ }
169175
170176 /// <summary>
171177 /// Creates a <see cref="PolicyWrap" /> of the given policies governing delegates returning values of type <typeparamref name="TResult" />.
@@ -174,11 +180,18 @@ public static AsyncPolicyWrap WrapAsync(params IAsyncPolicy[] policies) =>
174180 /// <typeparam name="TResult">The return type of delegates which may be executed through the policy.</typeparam>
175181 /// <returns>The PolicyWrap.</returns>
176182 /// <exception cref="ArgumentException">The enumerable of policies to form the wrap must contain at least two policies.</exception>
177- public static AsyncPolicyWrap < TResult > WrapAsync < TResult > ( params IAsyncPolicy < TResult > [ ] policies ) =>
178- policies . Length switch
183+ public static AsyncPolicyWrap < TResult > WrapAsync < TResult > ( params IAsyncPolicy < TResult > [ ] policies )
184+ {
185+ if ( policies is null )
186+ {
187+ throw new ArgumentNullException ( nameof ( policies ) ) ;
188+ }
189+
190+ return policies . Length switch
179191 {
180192 < MinimumPoliciesRequiredForWrap => throw new ArgumentException ( "The enumerable of policies to form the wrap must contain at least two policies." , nameof ( policies ) ) ,
181193 MinimumPoliciesRequiredForWrap => new AsyncPolicyWrap < TResult > ( ( AsyncPolicy < TResult > ) policies [ 0 ] , policies [ 1 ] ) ,
182194 _ => WrapAsync ( policies [ 0 ] , WrapAsync ( policies . Skip ( 1 ) . ToArray ( ) ) ) ,
183195 } ;
196+ }
184197}
0 commit comments