Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix IDE0011 warning #2085

Merged
merged 13 commits into from
Apr 29, 2024
8 changes: 8 additions & 0 deletions src/Polly/AsyncPolicy.ContextAndKeys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ public abstract partial class AsyncPolicy
public AsyncPolicy WithPolicyKey(string policyKey)
{
if (policyKeyInternal != null)
{
throw PolicyKeyMustBeImmutableException(nameof(policyKey));
}

policyKeyInternal = policyKey;
return this;
Expand All @@ -24,7 +26,9 @@ public AsyncPolicy WithPolicyKey(string policyKey)
IAsyncPolicy IAsyncPolicy.WithPolicyKey(string policyKey)
{
if (policyKeyInternal != null)
{
throw PolicyKeyMustBeImmutableException(nameof(policyKey));
}

policyKeyInternal = policyKey;
return this;
Expand All @@ -41,7 +45,9 @@ public abstract partial class AsyncPolicy<TResult>
public AsyncPolicy<TResult> WithPolicyKey(string policyKey)
{
if (policyKeyInternal != null)
{
throw PolicyKeyMustBeImmutableException(nameof(policyKey));
}

policyKeyInternal = policyKey;
return this;
Expand All @@ -55,7 +61,9 @@ public AsyncPolicy<TResult> WithPolicyKey(string policyKey)
IAsyncPolicy<TResult> IAsyncPolicy<TResult>.WithPolicyKey(string policyKey)
{
if (policyKeyInternal != null)
{
throw PolicyKeyMustBeImmutableException(nameof(policyKey));
}

policyKeyInternal = policyKey;
return this;
Expand Down
8 changes: 8 additions & 0 deletions src/Polly/AsyncPolicy.ExecuteOverloads.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ public Task ExecuteAsync(Func<Context, CancellationToken, Task> action, IDiction
public async Task ExecuteAsync(Func<Context, CancellationToken, Task> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}

SetPolicyContext(context, out string priorPolicyWrapKey, out string priorPolicyKey);

Expand Down Expand Up @@ -218,7 +220,9 @@ public Task<TResult> ExecuteAsync<TResult>(Func<Context, CancellationToken, Task
public async Task<TResult> ExecuteAsync<TResult>(Func<Context, CancellationToken, Task<TResult>> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}

SetPolicyContext(context, out string priorPolicyWrapKey, out string priorPolicyKey);

Expand Down Expand Up @@ -335,7 +339,9 @@ public Task<PolicyResult> ExecuteAndCaptureAsync(Func<Context, CancellationToken
public async Task<PolicyResult> ExecuteAndCaptureAsync(Func<Context, CancellationToken, Task> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}

try
{
Expand Down Expand Up @@ -460,7 +466,9 @@ public Task<PolicyResult<TResult>> ExecuteAndCaptureAsync<TResult>(Func<Context,
public async Task<PolicyResult<TResult>> ExecuteAndCaptureAsync<TResult>(Func<Context, CancellationToken, Task<TResult>> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}

try
{
Expand Down
4 changes: 4 additions & 0 deletions src/Polly/AsyncPolicy.TResult.ExecuteOverloads.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ public Task<TResult> ExecuteAsync(Func<Context, CancellationToken, Task<TResult>
public async Task<TResult> ExecuteAsync(Func<Context, CancellationToken, Task<TResult>> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}

SetPolicyContext(context, out string priorPolicyWrapKey, out string priorPolicyKey);

Expand Down Expand Up @@ -222,7 +224,9 @@ public Task<PolicyResult<TResult>> ExecuteAndCaptureAsync(Func<Context, Cancella
public async Task<PolicyResult<TResult>> ExecuteAndCaptureAsync(Func<Context, CancellationToken, Task<TResult>> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}

try
{
Expand Down
8 changes: 8 additions & 0 deletions src/Polly/Bulkhead/AsyncBulkheadSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,19 @@ public static AsyncBulkheadPolicy BulkheadAsync(
Func<Context, Task> onBulkheadRejectedAsync)
{
if (maxParallelization <= 0)
{
throw new ArgumentOutOfRangeException(nameof(maxParallelization), "Value must be greater than zero.");
}

if (maxQueuingActions < 0)
{
throw new ArgumentOutOfRangeException(nameof(maxQueuingActions), "Value must be greater than or equal to zero.");
}

if (onBulkheadRejectedAsync == null)
{
throw new ArgumentNullException(nameof(onBulkheadRejectedAsync));
}

return new AsyncBulkheadPolicy(
maxParallelization,
Expand Down
8 changes: 8 additions & 0 deletions src/Polly/Bulkhead/AsyncBulkheadTResultSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,19 @@ public static AsyncBulkheadPolicy<TResult> BulkheadAsync<TResult>(int maxParalle
public static AsyncBulkheadPolicy<TResult> BulkheadAsync<TResult>(int maxParallelization, int maxQueuingActions, Func<Context, Task> onBulkheadRejectedAsync)
{
if (maxParallelization <= 0)
{
throw new ArgumentOutOfRangeException(nameof(maxParallelization), "Value must be greater than zero.");
}

if (maxQueuingActions < 0)
{
throw new ArgumentOutOfRangeException(nameof(maxQueuingActions), "Value must be greater than or equal to zero.");
}

if (onBulkheadRejectedAsync == null)
{
throw new ArgumentNullException(nameof(onBulkheadRejectedAsync));
}

return new AsyncBulkheadPolicy<TResult>(
maxParallelization,
Expand Down
8 changes: 8 additions & 0 deletions src/Polly/Bulkhead/BulkheadSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,19 @@ public static BulkheadPolicy Bulkhead(int maxParallelization, int maxQueuingActi
public static BulkheadPolicy Bulkhead(int maxParallelization, int maxQueuingActions, Action<Context> onBulkheadRejected)
{
if (maxParallelization <= 0)
{
throw new ArgumentOutOfRangeException(nameof(maxParallelization), "Value must be greater than zero.");
}

if (maxQueuingActions < 0)
{
throw new ArgumentOutOfRangeException(nameof(maxQueuingActions), "Value must be greater than or equal to zero.");
}

if (onBulkheadRejected == null)
{
throw new ArgumentNullException(nameof(onBulkheadRejected));
}

return new BulkheadPolicy(
maxParallelization,
Expand Down
8 changes: 8 additions & 0 deletions src/Polly/Bulkhead/BulkheadTResultSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,19 @@ public static BulkheadPolicy<TResult> Bulkhead<TResult>(int maxParallelization,
public static BulkheadPolicy<TResult> Bulkhead<TResult>(int maxParallelization, int maxQueuingActions, Action<Context> onBulkheadRejected)
{
if (maxParallelization <= 0)
{
throw new ArgumentOutOfRangeException(nameof(maxParallelization), "Value must be greater than zero.");
}

if (maxQueuingActions < 0)
{
throw new ArgumentOutOfRangeException(nameof(maxQueuingActions), "Value must be greater than or equal to zero.");
}

if (onBulkheadRejected == null)
{
throw new ArgumentNullException(nameof(onBulkheadRejected));
}

return new BulkheadPolicy<TResult>(
maxParallelization,
Expand Down
32 changes: 32 additions & 0 deletions src/Polly/Caching/AsyncCacheSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,19 @@ public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider cacheProvider, Tim
public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider cacheProvider, ITtlStrategy ttlStrategy, ICacheKeyStrategy cacheKeyStrategy, Action<Context, string, Exception>? onCacheError = null)
{
if (cacheProvider == null)
{
throw new ArgumentNullException(nameof(cacheProvider));
}

if (ttlStrategy == null)
{
throw new ArgumentNullException(nameof(ttlStrategy));
}

if (cacheKeyStrategy == null)
{
throw new ArgumentNullException(nameof(cacheKeyStrategy));
}

Action<Context, string> emptyDelegate = (_, _) => { };

Expand Down Expand Up @@ -109,11 +117,19 @@ public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider cacheProvider, Tim
public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider cacheProvider, ITtlStrategy ttlStrategy, Func<Context, string> cacheKeyStrategy, Action<Context, string, Exception>? onCacheError = null)
{
if (cacheProvider == null)
{
throw new ArgumentNullException(nameof(cacheProvider));
}

if (ttlStrategy == null)
{
throw new ArgumentNullException(nameof(ttlStrategy));
}

if (cacheKeyStrategy == null)
{
throw new ArgumentNullException(nameof(cacheKeyStrategy));
}

Action<Context, string> emptyDelegate = (_, _) => { };

Expand Down Expand Up @@ -303,18 +319,34 @@ public static AsyncCachePolicy CacheAsync(
Action<Context, string, Exception>? onCachePutError)
{
if (cacheProvider == null)
{
throw new ArgumentNullException(nameof(cacheProvider));
}

if (ttlStrategy == null)
{
throw new ArgumentNullException(nameof(ttlStrategy));
}

if (cacheKeyStrategy == null)
{
throw new ArgumentNullException(nameof(cacheKeyStrategy));
}

if (onCacheGet == null)
{
throw new ArgumentNullException(nameof(onCacheGet));
}

if (onCacheMiss == null)
{
throw new ArgumentNullException(nameof(onCacheMiss));
}

if (onCachePut == null)
{
throw new ArgumentNullException(nameof(onCachePut));
}

return new AsyncCachePolicy(cacheProvider, ttlStrategy, cacheKeyStrategy, onCacheGet, onCacheMiss, onCachePut, onCacheGetError, onCachePutError);
}
Expand Down
Loading