Skip to content

Commit 4f02c66

Browse files
authored
Fix CA1068 warnings (#2182)
* Fix CA1068 for public classes * Fix CA1068 for internal methods
1 parent c93aeff commit 4f02c66

39 files changed

+190
-140
lines changed

src/Polly/AsyncPolicy.GenericImplementation.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
public abstract partial class AsyncPolicy<TResult>
44
{
5+
#pragma warning disable CA1068
56
/// <summary>
67
/// Defines the implementation of a policy for async executions returning <typeparamref name="TResult"/>.
78
/// </summary>
@@ -15,4 +16,5 @@ protected abstract Task<TResult> ImplementationAsync(
1516
Context context,
1617
CancellationToken cancellationToken,
1718
bool continueOnCapturedContext);
19+
#pragma warning restore CA1068
1820
}

src/Polly/AsyncPolicy.NonGenericImplementation.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
public abstract partial class AsyncPolicy
44
{
5+
#pragma warning disable CA1068
56
/// <summary>
67
/// Defines the implementation of a policy for async executions with no return value.
78
/// </summary>
@@ -16,11 +17,13 @@ protected virtual Task ImplementationAsync(
1617
CancellationToken cancellationToken,
1718
bool continueOnCapturedContext) =>
1819
ImplementationAsync<EmptyStruct>(async (ctx, token) =>
20+
#pragma warning restore CA1068
1921
{
2022
await action(ctx, token).ConfigureAwait(continueOnCapturedContext);
2123
return EmptyStruct.Instance;
2224
}, context, cancellationToken, continueOnCapturedContext);
2325

26+
#pragma warning disable CA1068
2427
/// <summary>
2528
/// Defines the implementation of a policy for async executions returning <typeparamref name="TResult"/>.
2629
/// </summary>
@@ -35,4 +38,5 @@ protected abstract Task<TResult> ImplementationAsync<TResult>(
3538
Context context,
3639
CancellationToken cancellationToken,
3740
bool continueOnCapturedContext);
41+
#pragma warning restore CA1068
3842
}

src/Polly/Bulkhead/AsyncBulkheadEngine.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ internal static async Task<TResult> ImplementationAsync<TResult>(
99
Func<Context, Task> onBulkheadRejectedAsync,
1010
SemaphoreSlim maxParallelizationSemaphore,
1111
SemaphoreSlim maxQueuedActionsSemaphore,
12-
CancellationToken cancellationToken,
13-
bool continueOnCapturedContext)
12+
bool continueOnCapturedContext,
13+
CancellationToken cancellationToken)
1414
{
1515
if (!await maxQueuedActionsSemaphore.WaitAsync(TimeSpan.Zero, cancellationToken).ConfigureAwait(continueOnCapturedContext))
1616
{

src/Polly/Bulkhead/AsyncBulkheadPolicy.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ internal AsyncBulkheadPolicy(
3636
[DebuggerStepThrough]
3737
protected override Task<TResult> ImplementationAsync<TResult>(Func<Context, CancellationToken, Task<TResult>> action, Context context, CancellationToken cancellationToken,
3838
bool continueOnCapturedContext) =>
39-
AsyncBulkheadEngine.ImplementationAsync(action, context, _onBulkheadRejectedAsync, _maxParallelizationSemaphore, _maxQueuedActionsSemaphore, cancellationToken, continueOnCapturedContext);
39+
AsyncBulkheadEngine.ImplementationAsync(action, context, _onBulkheadRejectedAsync, _maxParallelizationSemaphore, _maxQueuedActionsSemaphore, continueOnCapturedContext, cancellationToken);
4040

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

7676
/// <summary>
7777
/// Gets the number of slots currently available for executing actions through the bulkhead.

src/Polly/Caching/AsyncCacheEngine.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ internal static async Task<TResult> ImplementationAsync<TResult>(
99
Func<Context, string> cacheKeyStrategy,
1010
Func<Context, CancellationToken, Task<TResult>> action,
1111
Context context,
12-
CancellationToken cancellationToken,
1312
bool continueOnCapturedContext,
1413
Action<Context, string> onCacheGet,
1514
Action<Context, string> onCacheMiss,
1615
Action<Context, string> onCachePut,
1716
Action<Context, string, Exception>? onCacheGetError,
18-
Action<Context, string, Exception>? onCachePutError)
17+
Action<Context, string, Exception>? onCachePutError,
18+
CancellationToken cancellationToken)
1919
{
2020
cancellationToken.ThrowIfCancellationRequested();
2121

src/Polly/Caching/AsyncCachePolicy.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ protected override Task<TResult> ImplementationAsync<TResult>(Func<Context, Canc
5454
_cacheKeyStrategy,
5555
action,
5656
context,
57-
cancellationToken,
5857
continueOnCapturedContext,
5958
_onCacheGet,
6059
_onCacheMiss,
6160
_onCachePut,
6261
_onCacheGetError,
63-
_onCachePutError);
62+
_onCachePutError,
63+
cancellationToken);
6464
}
6565

6666
/// <summary>
@@ -111,12 +111,12 @@ protected override Task<TResult> ImplementationAsync(Func<Context, CancellationT
111111
_cacheKeyStrategy,
112112
action,
113113
context,
114-
cancellationToken,
115114
continueOnCapturedContext,
116115
_onCacheGet,
117116
_onCacheMiss,
118117
_onCachePut,
119118
_onCacheGetError,
120-
_onCachePutError);
119+
_onCachePutError,
120+
cancellationToken);
121121
}
122122

src/Polly/Caching/CacheEngine.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ internal static TResult Implementation<TResult>(
99
Func<Context, string> cacheKeyStrategy,
1010
Func<Context, CancellationToken, TResult> action,
1111
Context context,
12-
CancellationToken cancellationToken,
1312
Action<Context, string> onCacheGet,
1413
Action<Context, string> onCacheMiss,
1514
Action<Context, string> onCachePut,
1615
Action<Context, string, Exception>? onCacheGetError,
17-
Action<Context, string, Exception>? onCachePutError)
16+
Action<Context, string, Exception>? onCachePutError,
17+
CancellationToken cancellationToken)
1818
{
1919
cancellationToken.ThrowIfCancellationRequested();
2020

src/Polly/Caching/CachePolicy.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ protected override TResult Implementation<TResult>(Func<Context, CancellationTok
5151
_cacheKeyStrategy,
5252
action,
5353
context,
54-
cancellationToken,
5554
_onCacheGet,
5655
_onCacheMiss,
5756
_onCachePut,
5857
_onCacheGetError,
59-
_onCachePutError);
58+
_onCachePutError,
59+
cancellationToken);
6060
}
6161

6262
/// <summary>
@@ -105,10 +105,10 @@ protected override TResult Implementation(Func<Context, CancellationToken, TResu
105105
_cacheKeyStrategy,
106106
action,
107107
context,
108-
cancellationToken,
109108
_onCacheGet,
110109
_onCacheMiss,
111110
_onCachePut,
112111
_onCacheGetError,
113-
_onCachePutError);
112+
_onCachePutError,
113+
cancellationToken);
114114
}

src/Polly/Caching/IAsyncCacheProvider.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace Polly.Caching;
77
public interface IAsyncCacheProvider
88
{
99
#pragma warning disable SA1414
10+
#pragma warning disable CA1068
1011
/// <summary>
1112
/// Gets a value from the cache asynchronously.
1213
/// </summary>
@@ -18,8 +19,10 @@ public interface IAsyncCacheProvider
1819
/// the key was found in the cache, and whose second element is the value from the cache (null if not found).
1920
/// </returns>
2021
Task<(bool, object?)> TryGetAsync(string key, CancellationToken cancellationToken, bool continueOnCapturedContext);
21-
#pragma warning restore SA1414
22+
#pragma warning restore CA1068
23+
#pragma warning restore SA1414
2224

25+
#pragma warning disable CA1068
2326
/// <summary>
2427
/// Puts the specified value in the cache asynchronously.
2528
/// </summary>
@@ -30,6 +33,7 @@ public interface IAsyncCacheProvider
3033
/// <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>
3134
/// <returns>A <see cref="Task" /> which completes when the value has been cached.</returns>
3235
Task PutAsync(string key, object? value, Ttl ttl, CancellationToken cancellationToken, bool continueOnCapturedContext);
36+
#pragma warning restore CA1068
3337
}
3438

3539
/// <summary>
@@ -39,6 +43,7 @@ public interface IAsyncCacheProvider
3943
public interface IAsyncCacheProvider<TResult>
4044
{
4145
#pragma warning disable SA1414
46+
#pragma warning disable CA1068
4247
/// <summary>
4348
/// Gets a value from the cache asynchronously.
4449
/// </summary>
@@ -50,8 +55,10 @@ public interface IAsyncCacheProvider<TResult>
5055
/// the key was found in the cache, and whose second element is the value from the cache (default(TResult) if not found).
5156
/// </returns>
5257
Task<(bool, TResult?)> TryGetAsync(string key, CancellationToken cancellationToken, bool continueOnCapturedContext);
58+
#pragma warning restore CA1068
5359
#pragma warning restore SA1414
5460

61+
#pragma warning disable CA1068
5562
/// <summary>
5663
/// Puts the specified value in the cache asynchronously.
5764
/// </summary>
@@ -62,4 +69,5 @@ public interface IAsyncCacheProvider<TResult>
6269
/// <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>
6370
/// <returns>A <see cref="Task" /> which completes when the value has been cached.</returns>
6471
Task PutAsync(string key, TResult? value, Ttl ttl, CancellationToken cancellationToken, bool continueOnCapturedContext);
72+
#pragma warning restore CA1068
6573
}

src/Polly/CircuitBreaker/AsyncCircuitBreakerEngine.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ internal class AsyncCircuitBreakerEngine
55
internal static async Task<TResult> ImplementationAsync<TResult>(
66
Func<Context, CancellationToken, Task<TResult>> action,
77
Context context,
8-
CancellationToken cancellationToken,
98
bool continueOnCapturedContext,
109
ExceptionPredicates shouldHandleExceptionPredicates,
1110
ResultPredicates<TResult> shouldHandleResultPredicates,
12-
ICircuitController<TResult> breakerController)
11+
ICircuitController<TResult> breakerController,
12+
CancellationToken cancellationToken)
1313
{
1414
cancellationToken.ThrowIfCancellationRequested();
1515

0 commit comments

Comments
 (0)