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 SA1501/IDE0055 #1957

Merged
merged 3 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/Polly/AsyncPolicy.ContextAndKeys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ public abstract partial class AsyncPolicy
/// <param name="policyKey">The unique, used-definable key to assign to this <see cref="AsyncPolicy"/> instance.</param>
public AsyncPolicy WithPolicyKey(string policyKey)
{
if (policyKeyInternal != null) throw PolicyKeyMustBeImmutableException(nameof(policyKey));
if (policyKeyInternal != null)
throw PolicyKeyMustBeImmutableException(nameof(policyKey));

policyKeyInternal = policyKey;
return this;
Expand All @@ -22,7 +23,8 @@ public AsyncPolicy WithPolicyKey(string policyKey)
/// <param name="policyKey">The unique, used-definable key to assign to this <see cref="IAsyncPolicy"/> instance.</param>
IAsyncPolicy IAsyncPolicy.WithPolicyKey(string policyKey)
{
if (policyKeyInternal != null) throw PolicyKeyMustBeImmutableException(nameof(policyKey));
if (policyKeyInternal != null)
throw PolicyKeyMustBeImmutableException(nameof(policyKey));

policyKeyInternal = policyKey;
return this;
Expand All @@ -38,7 +40,8 @@ public abstract partial class AsyncPolicy<TResult>
/// <param name="policyKey">The unique, used-definable key to assign to this <see cref="AsyncPolicy{TResult}"/> instance.</param>
public AsyncPolicy<TResult> WithPolicyKey(string policyKey)
{
if (policyKeyInternal != null) throw PolicyKeyMustBeImmutableException(nameof(policyKey));
if (policyKeyInternal != null)
throw PolicyKeyMustBeImmutableException(nameof(policyKey));

policyKeyInternal = policyKey;
return this;
Expand All @@ -51,7 +54,8 @@ public AsyncPolicy<TResult> WithPolicyKey(string policyKey)
/// <param name="policyKey">The unique, used-definable key to assign to this <see cref="IAsyncPolicy{TResult}"/> instance.</param>
IAsyncPolicy<TResult> IAsyncPolicy<TResult>.WithPolicyKey(string policyKey)
{
if (policyKeyInternal != null) throw PolicyKeyMustBeImmutableException(nameof(policyKey));
if (policyKeyInternal != null)
throw PolicyKeyMustBeImmutableException(nameof(policyKey));

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

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

Expand Down Expand Up @@ -213,7 +214,8 @@ public Task<TResult> ExecuteAsync<TResult>(Func<Context, CancellationToken, Task
[DebuggerStepThrough]
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));
if (context == null)
throw new ArgumentNullException(nameof(context));

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

Expand Down Expand Up @@ -329,7 +331,8 @@ public Task<PolicyResult> ExecuteAndCaptureAsync(Func<Context, CancellationToken
[DebuggerStepThrough]
public async Task<PolicyResult> ExecuteAndCaptureAsync(Func<Context, CancellationToken, Task> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext)
{
if (context == null) throw new ArgumentNullException(nameof(context));
if (context == null)
throw new ArgumentNullException(nameof(context));

try
{
Expand Down Expand Up @@ -453,7 +456,8 @@ public Task<PolicyResult<TResult>> ExecuteAndCaptureAsync<TResult>(Func<Context,
[DebuggerStepThrough]
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));
if (context == null)
throw new ArgumentNullException(nameof(context));

try
{
Expand Down
6 changes: 4 additions & 2 deletions src/Polly/AsyncPolicy.TResult.ExecuteOverloads.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ public Task<TResult> ExecuteAsync(Func<Context, CancellationToken, Task<TResult>
[DebuggerStepThrough]
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));
if (context == null)
throw new ArgumentNullException(nameof(context));

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

Expand Down Expand Up @@ -220,7 +221,8 @@ public Task<PolicyResult<TResult>> ExecuteAndCaptureAsync(Func<Context, Cancella
[DebuggerStepThrough]
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));
if (context == null)
throw new ArgumentNullException(nameof(context));

try
{
Expand Down
2 changes: 1 addition & 1 deletion src/Polly/Bulkhead/AsyncBulkheadEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace Polly.Bulkhead;

internal static class AsyncBulkheadEngine
{
internal static async Task<TResult> ImplementationAsync<TResult>(
internal static async Task<TResult> ImplementationAsync<TResult>(
Func<Context, CancellationToken, Task<TResult>> action,
Context context,
Func<Context, Task> onBulkheadRejectedAsync,
Expand Down
9 changes: 6 additions & 3 deletions src/Polly/Bulkhead/AsyncBulkheadSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,12 @@ public static AsyncBulkheadPolicy BulkheadAsync(
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));
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
9 changes: 6 additions & 3 deletions src/Polly/Bulkhead/AsyncBulkheadTResultSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@ public static AsyncBulkheadPolicy<TResult> BulkheadAsync<TResult>(int maxParalle
/// <exception cref="ArgumentNullException">onBulkheadRejectedAsync</exception>
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));
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
9 changes: 6 additions & 3 deletions src/Polly/Bulkhead/BulkheadSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@ public static BulkheadPolicy Bulkhead(int maxParallelization, int maxQueuingActi
/// <exception cref="ArgumentNullException">onBulkheadRejected</exception>
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));
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
9 changes: 6 additions & 3 deletions src/Polly/Bulkhead/BulkheadTResultSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@ public static BulkheadPolicy<TResult> Bulkhead<TResult>(int maxParallelization,
/// <exception cref="ArgumentNullException">onBulkheadRejected</exception>
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));
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
4 changes: 1 addition & 3 deletions src/Polly/Caching/AsyncCachePolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ protected override Task ImplementationAsync(
Func<Context, CancellationToken, Task> action,
Context context,
CancellationToken cancellationToken,
bool continueOnCapturedContext) =>
// Pass-through/NOOP policy action, for void-returning executions through the cache policy.
action(context, cancellationToken);
bool continueOnCapturedContext) => action(context, cancellationToken); // Pass-through/NOOP policy action, for void-returning executions through the cache policy.

/// <inheritdoc/>
[DebuggerStepThrough]
Expand Down
36 changes: 24 additions & 12 deletions src/Polly/Caching/AsyncCacheSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,12 @@
/// <exception cref="ArgumentNullException">cacheKeyStrategy</exception>
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));
if (cacheProvider == null)
throw new ArgumentNullException(nameof(cacheProvider));

Check warning on line 68 in src/Polly/Caching/AsyncCacheSyntax.cs

View check run for this annotation

Codecov / codecov/patch

src/Polly/Caching/AsyncCacheSyntax.cs#L68

Added line #L68 was not covered by tests
if (ttlStrategy == null)
throw new ArgumentNullException(nameof(ttlStrategy));

Check warning on line 70 in src/Polly/Caching/AsyncCacheSyntax.cs

View check run for this annotation

Codecov / codecov/patch

src/Polly/Caching/AsyncCacheSyntax.cs#L70

Added line #L70 was not covered by tests
if (cacheKeyStrategy == null)
throw new ArgumentNullException(nameof(cacheKeyStrategy));

Check warning on line 72 in src/Polly/Caching/AsyncCacheSyntax.cs

View check run for this annotation

Codecov / codecov/patch

src/Polly/Caching/AsyncCacheSyntax.cs#L72

Added line #L72 was not covered by tests

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

Expand Down Expand Up @@ -105,9 +108,12 @@
/// <exception cref="ArgumentNullException">cacheKeyStrategy</exception>
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));
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 @@ -296,13 +302,19 @@
Action<Context, string, Exception>? onCacheGetError,
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 (cacheProvider == null)
throw new ArgumentNullException(nameof(cacheProvider));

Check warning on line 306 in src/Polly/Caching/AsyncCacheSyntax.cs

View check run for this annotation

Codecov / codecov/patch

src/Polly/Caching/AsyncCacheSyntax.cs#L306

Added line #L306 was not covered by tests
if (ttlStrategy == null)
throw new ArgumentNullException(nameof(ttlStrategy));

Check warning on line 308 in src/Polly/Caching/AsyncCacheSyntax.cs

View check run for this annotation

Codecov / codecov/patch

src/Polly/Caching/AsyncCacheSyntax.cs#L308

Added line #L308 was not covered by tests
if (cacheKeyStrategy == null)
throw new ArgumentNullException(nameof(cacheKeyStrategy));

Check warning on line 310 in src/Polly/Caching/AsyncCacheSyntax.cs

View check run for this annotation

Codecov / codecov/patch

src/Polly/Caching/AsyncCacheSyntax.cs#L310

Added line #L310 was not covered by tests

if (onCacheGet == null) throw new ArgumentNullException(nameof(onCacheGet));
if (onCacheMiss == null) throw new ArgumentNullException(nameof(onCacheMiss));
if (onCachePut == null) throw new ArgumentNullException(nameof(onCachePut));
if (onCacheGet == null)
throw new ArgumentNullException(nameof(onCacheGet));

Check warning on line 313 in src/Polly/Caching/AsyncCacheSyntax.cs

View check run for this annotation

Codecov / codecov/patch

src/Polly/Caching/AsyncCacheSyntax.cs#L313

Added line #L313 was not covered by tests
if (onCacheMiss == null)
throw new ArgumentNullException(nameof(onCacheMiss));

Check warning on line 315 in src/Polly/Caching/AsyncCacheSyntax.cs

View check run for this annotation

Codecov / codecov/patch

src/Polly/Caching/AsyncCacheSyntax.cs#L315

Added line #L315 was not covered by tests
if (onCachePut == null)
throw new ArgumentNullException(nameof(onCachePut));

Check warning on line 317 in src/Polly/Caching/AsyncCacheSyntax.cs

View check run for this annotation

Codecov / codecov/patch

src/Polly/Caching/AsyncCacheSyntax.cs#L317

Added line #L317 was not covered by tests

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