From 6bb905f1adebcfab04c1bff79fc7bc1f7b20a21b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Baranyai=20M=C3=A1t=C3=A9?= Date: Fri, 26 Jan 2024 11:19:23 +0100 Subject: [PATCH] Fix IDE0044 warnings (#1928) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Baranyai Máté --- src/Polly/Bulkhead/AsyncBulkheadPolicy.cs | 4 ++-- src/Polly/Caching/CachePolicy.cs | 2 +- src/Polly/Fallback/AsyncFallbackPolicy.cs | 8 ++++---- src/Polly/Fallback/FallbackPolicy.cs | 8 ++++---- src/Polly/Polly.csproj | 2 +- src/Polly/Timeout/AsyncTimeoutPolicy.cs | 4 ++-- src/Polly/Timeout/TimeoutPolicy.cs | 8 ++++---- src/Polly/Utilities/TimedLock.cs | 16 ++++++++-------- 8 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/Polly/Bulkhead/AsyncBulkheadPolicy.cs b/src/Polly/Bulkhead/AsyncBulkheadPolicy.cs index a5df546878c..f4f269580ff 100644 --- a/src/Polly/Bulkhead/AsyncBulkheadPolicy.cs +++ b/src/Polly/Bulkhead/AsyncBulkheadPolicy.cs @@ -9,7 +9,7 @@ public class AsyncBulkheadPolicy : AsyncPolicy, IBulkheadPolicy private readonly SemaphoreSlim _maxParallelizationSemaphore; private readonly SemaphoreSlim _maxQueuedActionsSemaphore; private readonly int _maxQueueingActions; - private Func _onBulkheadRejectedAsync; + private readonly Func _onBulkheadRejectedAsync; internal AsyncBulkheadPolicy( int maxParallelization, @@ -55,7 +55,7 @@ public class AsyncBulkheadPolicy : AsyncPolicy, IBulkheadPolic private readonly SemaphoreSlim _maxParallelizationSemaphore; private readonly SemaphoreSlim _maxQueuedActionsSemaphore; private readonly int _maxQueueingActions; - private Func _onBulkheadRejectedAsync; + private readonly Func _onBulkheadRejectedAsync; internal AsyncBulkheadPolicy( int maxParallelization, diff --git a/src/Polly/Caching/CachePolicy.cs b/src/Polly/Caching/CachePolicy.cs index cdc22d079f2..da58c7bca24 100644 --- a/src/Polly/Caching/CachePolicy.cs +++ b/src/Polly/Caching/CachePolicy.cs @@ -72,7 +72,7 @@ public class CachePolicy : Policy, ICachePolicy private readonly ISyncCacheProvider _syncCacheProvider; private readonly ITtlStrategy _ttlStrategy; - private Func _cacheKeyStrategy; + private readonly Func _cacheKeyStrategy; internal CachePolicy( ISyncCacheProvider syncCacheProvider, diff --git a/src/Polly/Fallback/AsyncFallbackPolicy.cs b/src/Polly/Fallback/AsyncFallbackPolicy.cs index 8016d3b1dbe..284d8a6cef8 100644 --- a/src/Polly/Fallback/AsyncFallbackPolicy.cs +++ b/src/Polly/Fallback/AsyncFallbackPolicy.cs @@ -7,8 +7,8 @@ namespace Polly.Fallback; /// public class AsyncFallbackPolicy : AsyncPolicy, IFallbackPolicy { - private Func _onFallbackAsync; - private Func _fallbackAction; + private readonly Func _onFallbackAsync; + private readonly Func _fallbackAction; internal AsyncFallbackPolicy(PolicyBuilder policyBuilder, Func onFallbackAsync, Func fallbackAction) @@ -54,8 +54,8 @@ protected override Task ImplementationAsync(FuncThe return type of delegates which may be executed through the policy. public class AsyncFallbackPolicy : AsyncPolicy, IFallbackPolicy { - private Func, Context, Task> _onFallbackAsync; - private Func, Context, CancellationToken, Task> _fallbackAction; + private readonly Func, Context, Task> _onFallbackAsync; + private readonly Func, Context, CancellationToken, Task> _fallbackAction; internal AsyncFallbackPolicy( PolicyBuilder policyBuilder, diff --git a/src/Polly/Fallback/FallbackPolicy.cs b/src/Polly/Fallback/FallbackPolicy.cs index 0f4f8a44929..c4cb6c58819 100644 --- a/src/Polly/Fallback/FallbackPolicy.cs +++ b/src/Polly/Fallback/FallbackPolicy.cs @@ -7,8 +7,8 @@ namespace Polly.Fallback; /// public class FallbackPolicy : Policy, IFallbackPolicy { - private Action _onFallback; - private Action _fallbackAction; + private readonly Action _onFallback; + private readonly Action _fallbackAction; internal FallbackPolicy( PolicyBuilder policyBuilder, @@ -50,8 +50,8 @@ protected override TResult Implementation(Func public class FallbackPolicy : Policy, IFallbackPolicy { - private Action, Context> _onFallback; - private Func, Context, CancellationToken, TResult> _fallbackAction; + private readonly Action, Context> _onFallback; + private readonly Func, Context, CancellationToken, TResult> _fallbackAction; internal FallbackPolicy( PolicyBuilder policyBuilder, diff --git a/src/Polly/Polly.csproj b/src/Polly/Polly.csproj index 8499c30dad6..817ad4d631c 100644 --- a/src/Polly/Polly.csproj +++ b/src/Polly/Polly.csproj @@ -7,7 +7,7 @@ 70 true $(NoWarn);IDE0011;SA1501;S103;IDE0055;SA1111;IDE0066;S3872;SA1127;SA1128;SA1402;SA1513;SA1414;S3215;S2955 - $(NoWarn);IDE0044;IDE1006;CA1062;S107;CA1068;S4039;SA1121;CA1000;CA1063;SA1113;CA1031;CA1051;CA1200 + $(NoWarn);IDE1006;CA1062;S107;CA1068;S4039;SA1121;CA1000;CA1063;SA1113;CA1031;CA1051;CA1200 $(NoWarn);SA1629;SA1612;CA2211;S2223;CA1032;CA1815;CA1816;S4457;SA1615;IDE0250;S109;SA1618;SA1407;CA1033 $(NoWarn);SA1515;S4023;CA1010;IDE0063;S2681;S3442;S3880;CA1064;SA1110;SA1203;SA1649;SA1625;SA1623;SA1118 $(NoWarn);S3253;S3971;S6605;CA1724;CA1716;SA1108;CA1710;S4049;S3246 diff --git a/src/Polly/Timeout/AsyncTimeoutPolicy.cs b/src/Polly/Timeout/AsyncTimeoutPolicy.cs index 3f280d96987..6019d3f7a58 100644 --- a/src/Polly/Timeout/AsyncTimeoutPolicy.cs +++ b/src/Polly/Timeout/AsyncTimeoutPolicy.cs @@ -44,8 +44,8 @@ protected override Task ImplementationAsync( public class AsyncTimeoutPolicy : AsyncPolicy, ITimeoutPolicy { private readonly TimeoutStrategy _timeoutStrategy; - private Func _timeoutProvider; - private Func _onTimeoutAsync; + private readonly Func _timeoutProvider; + private readonly Func _onTimeoutAsync; internal AsyncTimeoutPolicy( Func timeoutProvider, diff --git a/src/Polly/Timeout/TimeoutPolicy.cs b/src/Polly/Timeout/TimeoutPolicy.cs index 49083d7a486..0f9390ed66f 100644 --- a/src/Polly/Timeout/TimeoutPolicy.cs +++ b/src/Polly/Timeout/TimeoutPolicy.cs @@ -6,8 +6,8 @@ public class TimeoutPolicy : Policy, ITimeoutPolicy { private readonly TimeoutStrategy _timeoutStrategy; - private Func _timeoutProvider; - private Action _onTimeout; + private readonly Func _timeoutProvider; + private readonly Action _onTimeout; internal TimeoutPolicy( Func timeoutProvider, @@ -37,8 +37,8 @@ protected override TResult Implementation(Func : Policy, ITimeoutPolicy { private readonly TimeoutStrategy _timeoutStrategy; - private Func _timeoutProvider; - private Action _onTimeout; + private readonly Func _timeoutProvider; + private readonly Action _onTimeout; internal TimeoutPolicy( Func timeoutProvider, diff --git a/src/Polly/Utilities/TimedLock.cs b/src/Polly/Utilities/TimedLock.cs index 1613216ceda..23628c60ea8 100644 --- a/src/Polly/Utilities/TimedLock.cs +++ b/src/Polly/Utilities/TimedLock.cs @@ -32,7 +32,7 @@ private static TimedLock Lock(object o, TimeSpan timeout) if (!Monitor.TryEnter(o, timeout)) { #if DEBUG - GC.SuppressFinalize(tl.leakDetector); + GC.SuppressFinalize(tl._leakDetector); #endif throw new LockTimeoutException(); } @@ -42,24 +42,24 @@ private static TimedLock Lock(object o, TimeSpan timeout) #if DEBUG private TimedLock(object o) { - target = o; - leakDetector = new Sentinel(); + _target = o; + _leakDetector = new Sentinel(); } #else - private TimedLock(object o) => target = o; + private TimedLock(object o) => _target = o; #endif - private object target; + private readonly object _target; public void Dispose() { - Monitor.Exit(target); + Monitor.Exit(_target); // It's a bad error if someone forgets to call Dispose, // so in Debug builds, we put a finalizer in to detect // the error. If Dispose is called, we suppress the // finalizer. #if DEBUG - GC.SuppressFinalize(leakDetector); + GC.SuppressFinalize(_leakDetector); #endif } @@ -78,7 +78,7 @@ private class Sentinel #endif } } - private Sentinel leakDetector; + private readonly Sentinel _leakDetector; #endif }