Skip to content

Commit

Permalink
Fix CA1068 warnings (#2182)
Browse files Browse the repository at this point in the history
* Fix CA1068 for public classes

* Fix CA1068 for internal methods
  • Loading branch information
iamdmitrij authored Jul 8, 2024
1 parent c93aeff commit 4f02c66
Show file tree
Hide file tree
Showing 39 changed files with 190 additions and 140 deletions.
2 changes: 2 additions & 0 deletions src/Polly/AsyncPolicy.GenericImplementation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

public abstract partial class AsyncPolicy<TResult>
{
#pragma warning disable CA1068
/// <summary>
/// Defines the implementation of a policy for async executions returning <typeparamref name="TResult"/>.
/// </summary>
Expand All @@ -15,4 +16,5 @@ protected abstract Task<TResult> ImplementationAsync(
Context context,
CancellationToken cancellationToken,
bool continueOnCapturedContext);
#pragma warning restore CA1068
}
4 changes: 4 additions & 0 deletions src/Polly/AsyncPolicy.NonGenericImplementation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

public abstract partial class AsyncPolicy
{
#pragma warning disable CA1068
/// <summary>
/// Defines the implementation of a policy for async executions with no return value.
/// </summary>
Expand All @@ -16,11 +17,13 @@ protected virtual Task ImplementationAsync(
CancellationToken cancellationToken,
bool continueOnCapturedContext) =>
ImplementationAsync<EmptyStruct>(async (ctx, token) =>
#pragma warning restore CA1068
{
await action(ctx, token).ConfigureAwait(continueOnCapturedContext);
return EmptyStruct.Instance;
}, context, cancellationToken, continueOnCapturedContext);

#pragma warning disable CA1068
/// <summary>
/// Defines the implementation of a policy for async executions returning <typeparamref name="TResult"/>.
/// </summary>
Expand All @@ -35,4 +38,5 @@ protected abstract Task<TResult> ImplementationAsync<TResult>(
Context context,
CancellationToken cancellationToken,
bool continueOnCapturedContext);
#pragma warning restore CA1068
}
4 changes: 2 additions & 2 deletions src/Polly/Bulkhead/AsyncBulkheadEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ internal static async Task<TResult> ImplementationAsync<TResult>(
Func<Context, Task> onBulkheadRejectedAsync,
SemaphoreSlim maxParallelizationSemaphore,
SemaphoreSlim maxQueuedActionsSemaphore,
CancellationToken cancellationToken,
bool continueOnCapturedContext)
bool continueOnCapturedContext,
CancellationToken cancellationToken)
{
if (!await maxQueuedActionsSemaphore.WaitAsync(TimeSpan.Zero, cancellationToken).ConfigureAwait(continueOnCapturedContext))
{
Expand Down
4 changes: 2 additions & 2 deletions src/Polly/Bulkhead/AsyncBulkheadPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ internal AsyncBulkheadPolicy(
[DebuggerStepThrough]
protected override Task<TResult> ImplementationAsync<TResult>(Func<Context, CancellationToken, Task<TResult>> action, Context context, CancellationToken cancellationToken,
bool continueOnCapturedContext) =>
AsyncBulkheadEngine.ImplementationAsync(action, context, _onBulkheadRejectedAsync, _maxParallelizationSemaphore, _maxQueuedActionsSemaphore, cancellationToken, continueOnCapturedContext);
AsyncBulkheadEngine.ImplementationAsync(action, context, _onBulkheadRejectedAsync, _maxParallelizationSemaphore, _maxQueuedActionsSemaphore, continueOnCapturedContext, cancellationToken);

/// <inheritdoc/>
public void Dispose()
Expand Down Expand Up @@ -71,7 +71,7 @@ internal AsyncBulkheadPolicy(
/// <inheritdoc/>
[DebuggerStepThrough]
protected override Task<TResult> ImplementationAsync(Func<Context, CancellationToken, Task<TResult>> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext) =>
AsyncBulkheadEngine.ImplementationAsync(action, context, _onBulkheadRejectedAsync, _maxParallelizationSemaphore, _maxQueuedActionsSemaphore, cancellationToken, continueOnCapturedContext);
AsyncBulkheadEngine.ImplementationAsync(action, context, _onBulkheadRejectedAsync, _maxParallelizationSemaphore, _maxQueuedActionsSemaphore, continueOnCapturedContext, cancellationToken);

/// <summary>
/// Gets the number of slots currently available for executing actions through the bulkhead.
Expand Down
4 changes: 2 additions & 2 deletions src/Polly/Caching/AsyncCacheEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ internal static async Task<TResult> ImplementationAsync<TResult>(
Func<Context, string> cacheKeyStrategy,
Func<Context, CancellationToken, Task<TResult>> action,
Context context,
CancellationToken cancellationToken,
bool continueOnCapturedContext,
Action<Context, string> onCacheGet,
Action<Context, string> onCacheMiss,
Action<Context, string> onCachePut,
Action<Context, string, Exception>? onCacheGetError,
Action<Context, string, Exception>? onCachePutError)
Action<Context, string, Exception>? onCachePutError,
CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();

Expand Down
8 changes: 4 additions & 4 deletions src/Polly/Caching/AsyncCachePolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ protected override Task<TResult> ImplementationAsync<TResult>(Func<Context, Canc
_cacheKeyStrategy,
action,
context,
cancellationToken,
continueOnCapturedContext,
_onCacheGet,
_onCacheMiss,
_onCachePut,
_onCacheGetError,
_onCachePutError);
_onCachePutError,
cancellationToken);
}

/// <summary>
Expand Down Expand Up @@ -111,12 +111,12 @@ protected override Task<TResult> ImplementationAsync(Func<Context, CancellationT
_cacheKeyStrategy,
action,
context,
cancellationToken,
continueOnCapturedContext,
_onCacheGet,
_onCacheMiss,
_onCachePut,
_onCacheGetError,
_onCachePutError);
_onCachePutError,
cancellationToken);
}

4 changes: 2 additions & 2 deletions src/Polly/Caching/CacheEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ internal static TResult Implementation<TResult>(
Func<Context, string> cacheKeyStrategy,
Func<Context, CancellationToken, TResult> action,
Context context,
CancellationToken cancellationToken,
Action<Context, string> onCacheGet,
Action<Context, string> onCacheMiss,
Action<Context, string> onCachePut,
Action<Context, string, Exception>? onCacheGetError,
Action<Context, string, Exception>? onCachePutError)
Action<Context, string, Exception>? onCachePutError,
CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();

Expand Down
8 changes: 4 additions & 4 deletions src/Polly/Caching/CachePolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ protected override TResult Implementation<TResult>(Func<Context, CancellationTok
_cacheKeyStrategy,
action,
context,
cancellationToken,
_onCacheGet,
_onCacheMiss,
_onCachePut,
_onCacheGetError,
_onCachePutError);
_onCachePutError,
cancellationToken);
}

/// <summary>
Expand Down Expand Up @@ -105,10 +105,10 @@ protected override TResult Implementation(Func<Context, CancellationToken, TResu
_cacheKeyStrategy,
action,
context,
cancellationToken,
_onCacheGet,
_onCacheMiss,
_onCachePut,
_onCacheGetError,
_onCachePutError);
_onCachePutError,
cancellationToken);
}
10 changes: 9 additions & 1 deletion src/Polly/Caching/IAsyncCacheProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace Polly.Caching;
public interface IAsyncCacheProvider
{
#pragma warning disable SA1414
#pragma warning disable CA1068
/// <summary>
/// Gets a value from the cache asynchronously.
/// </summary>
Expand All @@ -18,8 +19,10 @@ public interface IAsyncCacheProvider
/// the key was found in the cache, and whose second element is the value from the cache (null if not found).
/// </returns>
Task<(bool, object?)> TryGetAsync(string key, CancellationToken cancellationToken, bool continueOnCapturedContext);
#pragma warning restore SA1414
#pragma warning restore CA1068
#pragma warning restore SA1414

#pragma warning disable CA1068
/// <summary>
/// Puts the specified value in the cache asynchronously.
/// </summary>
Expand All @@ -30,6 +33,7 @@ public interface IAsyncCacheProvider
/// <param name="continueOnCapturedContext">Whether async calls should continue on a captured synchronization context.<para><remarks>Note: if the underlying cache's async API does not support controlling whether to continue on a captured context, async Policy executions with continueOnCapturedContext == true cannot be guaranteed to remain on the captured context.</remarks></para></param>
/// <returns>A <see cref="Task" /> which completes when the value has been cached.</returns>
Task PutAsync(string key, object? value, Ttl ttl, CancellationToken cancellationToken, bool continueOnCapturedContext);
#pragma warning restore CA1068
}

/// <summary>
Expand All @@ -39,6 +43,7 @@ public interface IAsyncCacheProvider
public interface IAsyncCacheProvider<TResult>
{
#pragma warning disable SA1414
#pragma warning disable CA1068
/// <summary>
/// Gets a value from the cache asynchronously.
/// </summary>
Expand All @@ -50,8 +55,10 @@ public interface IAsyncCacheProvider<TResult>
/// the key was found in the cache, and whose second element is the value from the cache (default(TResult) if not found).
/// </returns>
Task<(bool, TResult?)> TryGetAsync(string key, CancellationToken cancellationToken, bool continueOnCapturedContext);
#pragma warning restore CA1068
#pragma warning restore SA1414

#pragma warning disable CA1068
/// <summary>
/// Puts the specified value in the cache asynchronously.
/// </summary>
Expand All @@ -62,4 +69,5 @@ public interface IAsyncCacheProvider<TResult>
/// <param name="continueOnCapturedContext">Whether async calls should continue on a captured synchronization context.<para><remarks>Note: if the underlying cache's async API does not support controlling whether to continue on a captured context, async Policy executions with continueOnCapturedContext == true cannot be guaranteed to remain on the captured context.</remarks></para></param>
/// <returns>A <see cref="Task" /> which completes when the value has been cached.</returns>
Task PutAsync(string key, TResult? value, Ttl ttl, CancellationToken cancellationToken, bool continueOnCapturedContext);
#pragma warning restore CA1068
}
4 changes: 2 additions & 2 deletions src/Polly/CircuitBreaker/AsyncCircuitBreakerEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ internal class AsyncCircuitBreakerEngine
internal static async Task<TResult> ImplementationAsync<TResult>(
Func<Context, CancellationToken, Task<TResult>> action,
Context context,
CancellationToken cancellationToken,
bool continueOnCapturedContext,
ExceptionPredicates shouldHandleExceptionPredicates,
ResultPredicates<TResult> shouldHandleResultPredicates,
ICircuitController<TResult> breakerController)
ICircuitController<TResult> breakerController,
CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();

Expand Down
8 changes: 4 additions & 4 deletions src/Polly/CircuitBreaker/AsyncCircuitBreakerPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ protected override async Task<TResult> ImplementationAsync<TResult>(Func<Context
await AsyncCircuitBreakerEngine.ImplementationAsync<EmptyStruct>(
async (ctx, ct) => { result = await action(ctx, ct).ConfigureAwait(continueOnCapturedContext); return EmptyStruct.Instance; },
context,
cancellationToken,
continueOnCapturedContext,
ExceptionPredicates,
ResultPredicates<EmptyStruct>.None,
BreakerController).ConfigureAwait(continueOnCapturedContext);
BreakerController,
cancellationToken).ConfigureAwait(continueOnCapturedContext);
return result;
}
}
Expand Down Expand Up @@ -103,9 +103,9 @@ protected override Task<TResult> ImplementationAsync(Func<Context, CancellationT
AsyncCircuitBreakerEngine.ImplementationAsync(
action,
context,
cancellationToken,
continueOnCapturedContext,
ExceptionPredicates,
ResultPredicates,
BreakerController);
BreakerController,
cancellationToken);
}
4 changes: 2 additions & 2 deletions src/Polly/CircuitBreaker/CircuitBreakerEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ internal class CircuitBreakerEngine
internal static TResult Implementation<TResult>(
Func<Context, CancellationToken, TResult> action,
Context context,
CancellationToken cancellationToken,
ExceptionPredicates shouldHandleExceptionPredicates,
ResultPredicates<TResult> shouldHandleResultPredicates,
ICircuitController<TResult> breakerController)
ICircuitController<TResult> breakerController,
CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();

Expand Down
8 changes: 4 additions & 4 deletions src/Polly/CircuitBreaker/CircuitBreakerPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ protected override TResult Implementation<TResult>(Func<Context, CancellationTok
CircuitBreakerEngine.Implementation<EmptyStruct>(
(ctx, ct) => { result = action(ctx, ct); return EmptyStruct.Instance; },
context,
cancellationToken,
ExceptionPredicates,
ResultPredicates<EmptyStruct>.None,
BreakerController);
BreakerController,
cancellationToken);
return result;
}
}
Expand Down Expand Up @@ -101,8 +101,8 @@ protected override TResult Implementation(Func<Context, CancellationToken, TResu
CircuitBreakerEngine.Implementation(
action,
context,
cancellationToken,
ExceptionPredicates,
ResultPredicates,
BreakerController);
BreakerController,
cancellationToken);
}
4 changes: 2 additions & 2 deletions src/Polly/Fallback/AsyncFallbackEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ internal class AsyncFallbackEngine
internal static async Task<TResult> ImplementationAsync<TResult>(
Func<Context, CancellationToken, Task<TResult>> action,
Context context,
CancellationToken cancellationToken,
ExceptionPredicates shouldHandleExceptionPredicates,
ResultPredicates<TResult> shouldHandleResultPredicates,
Func<DelegateResult<TResult>, Context, Task> onFallbackAsync,
Func<DelegateResult<TResult>, Context, CancellationToken, Task<TResult>> fallbackAction,
bool continueOnCapturedContext)
bool continueOnCapturedContext,
CancellationToken cancellationToken)
{
DelegateResult<TResult> delegateOutcome;

Expand Down
8 changes: 4 additions & 4 deletions src/Polly/Fallback/AsyncFallbackPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ protected override Task ImplementationAsync(
return EmptyStruct.Instance;
},
context,
cancellationToken,
ExceptionPredicates,
ResultPredicates<EmptyStruct>.None,
(outcome, ctx) => _onFallbackAsync(outcome.Exception, ctx),
Expand All @@ -40,7 +39,8 @@ protected override Task ImplementationAsync(
await _fallbackAction(outcome.Exception, ctx, ct).ConfigureAwait(continueOnCapturedContext);
return EmptyStruct.Instance;
},
continueOnCapturedContext);
continueOnCapturedContext,
cancellationToken);

/// <inheritdoc/>
protected override Task<TResult> ImplementationAsync<TResult>(Func<Context, CancellationToken, Task<TResult>> action, Context context, CancellationToken cancellationToken,
Expand Down Expand Up @@ -77,10 +77,10 @@ protected override Task<TResult> ImplementationAsync(Func<Context, CancellationT
AsyncFallbackEngine.ImplementationAsync(
action,
context,
cancellationToken,
ExceptionPredicates,
ResultPredicates,
_onFallbackAsync,
_fallbackAction,
continueOnCapturedContext);
continueOnCapturedContext,
cancellationToken);
}
4 changes: 2 additions & 2 deletions src/Polly/Fallback/FallbackEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ internal static class FallbackEngine
internal static TResult Implementation<TResult>(
Func<Context, CancellationToken, TResult> action,
Context context,
CancellationToken cancellationToken,
ExceptionPredicates shouldHandleExceptionPredicates,
ResultPredicates<TResult> shouldHandleResultPredicates,
Action<DelegateResult<TResult>, Context> onFallback,
Func<DelegateResult<TResult>, Context, CancellationToken, TResult> fallbackAction)
Func<DelegateResult<TResult>, Context, CancellationToken, TResult> fallbackAction,
CancellationToken cancellationToken)
{
DelegateResult<TResult> delegateOutcome;

Expand Down
8 changes: 4 additions & 4 deletions src/Polly/Fallback/FallbackPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ protected override void Implementation(Action<Context, CancellationToken> action
return EmptyStruct.Instance;
},
context,
cancellationToken,
ExceptionPredicates,
ResultPredicates<EmptyStruct>.None,
(outcome, ctx) => _onFallback(outcome.Exception, ctx),
(outcome, ctx, ct) =>
{
_fallbackAction(outcome.Exception, ctx, ct);
return EmptyStruct.Instance;
});
},
cancellationToken);

/// <inheritdoc/>
protected override TResult Implementation<TResult>(Func<Context, CancellationToken, TResult> action, Context context, CancellationToken cancellationToken) =>
Expand Down Expand Up @@ -73,9 +73,9 @@ protected override TResult Implementation(Func<Context, CancellationToken, TResu
FallbackEngine.Implementation(
action,
context,
cancellationToken,
ExceptionPredicates,
ResultPredicates,
_onFallback,
_fallbackAction);
_fallbackAction,
cancellationToken);
}
Loading

0 comments on commit 4f02c66

Please sign in to comment.