From 9403059a03d5b149ef9691ef7f9f390a5c5dca1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Baranyai?= Date: Sun, 17 Mar 2024 09:02:18 +0100 Subject: [PATCH] Fix S3800/CA1821/S2955 --- src/Polly/Policy.HandleSyntax.cs | 4 ++-- src/Polly/PolicyBuilder.OrSyntax.cs | 4 ++-- src/Polly/Polly.csproj | 6 +++--- src/Polly/Utilities/TimedLock.cs | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Polly/Policy.HandleSyntax.cs b/src/Polly/Policy.HandleSyntax.cs index 0ece8b16278..bd1b6ebc4d0 100644 --- a/src/Polly/Policy.HandleSyntax.cs +++ b/src/Polly/Policy.HandleSyntax.cs @@ -61,7 +61,7 @@ public static PolicyBuilder HandleResult(Func r /// This policy filter matches the value returned using .Equals(), ideally suited for value types such as int and enum. To match characteristics of class return types, consider the overload taking a result predicate. /// The PolicyBuilder instance. public static PolicyBuilder HandleResult(TResult result) => - HandleResult(new Func(r => (r != null && r.Equals(result)) || (r == null && result == null))); + HandleResult(new Func(r => (!Equals(r, default(TResult)) && r.Equals(result)) || (Equals(r, default(TResult)) && Equals(result, default(TResult))))); } public partial class Policy @@ -123,5 +123,5 @@ public static PolicyBuilder HandleResult(Func resultPred /// This policy filter matches the value returned using .Equals(), ideally suited for value types such as int and enum. To match characteristics of class return types, consider the overload taking a result predicate. /// The PolicyBuilder instance. public static PolicyBuilder HandleResult(TResult result) => - HandleResult(r => (r != null && r.Equals(result)) || (r == null && result == null)); + HandleResult(r => (!Equals(r, default(TResult)) && r.Equals(result)) || (Equals(r, default(TResult)) && Equals(result, default(TResult)))); } diff --git a/src/Polly/PolicyBuilder.OrSyntax.cs b/src/Polly/PolicyBuilder.OrSyntax.cs index 43e5ab12922..27ce21e8cd2 100644 --- a/src/Polly/PolicyBuilder.OrSyntax.cs +++ b/src/Polly/PolicyBuilder.OrSyntax.cs @@ -102,7 +102,7 @@ public PolicyBuilder OrResult(Func resultPredic /// This policy filter matches the value returned using .Equals(), ideally suited for value types such as int and enum. To match characteristics of class return types, consider the overload taking a result predicate. /// The PolicyBuilder instance. public PolicyBuilder OrResult(TResult result) => - OrResult(r => (r != null && r.Equals(result)) || (r == null && result == null)); + OrResult(r => (!Equals(r, default(TResult)) && r.Equals(result)) || (Equals(r, default(TResult)) && Equals(result, default(TResult)))); #endregion } @@ -130,7 +130,7 @@ public PolicyBuilder OrResult(Func resultPredicate) /// This policy filter matches the value returned using .Equals(), ideally suited for value types such as int and enum. To match characteristics of class return types, consider the overload taking a result predicate. /// The PolicyBuilder instance. public PolicyBuilder OrResult(TResult result) => - OrResult(r => (r != null && r.Equals(result)) || (r == null && result == null)); + OrResult(r => (!Equals(r, default(TResult)) && r.Equals(result)) || (Equals(r, default(TResult)) && Equals(result, default(TResult)))); #endregion diff --git a/src/Polly/Polly.csproj b/src/Polly/Polly.csproj index 967d93bde1a..e128b592ed9 100644 --- a/src/Polly/Polly.csproj +++ b/src/Polly/Polly.csproj @@ -7,12 +7,12 @@ Library 70 true - $(NoWarn);IDE0011;S103;S3872;SA1402;SA1414;S3215;S2955 + $(NoWarn);IDE0011;S103;S3872;SA1402;SA1414;S3215 $(NoWarn);IDE1006;CA1062;S107;CA1068;S4039;CA1000;CA1063;CA1031;CA1051 $(NoWarn);CA2211;S2223;CA1032;CA1815;CA1816;S4457;SA1615;SA1618;CA1033 - $(NoWarn);S4023;CA1010;S3442;S3880;CA1064;SA1649;SA1625;SA1623;SA1118 + $(NoWarn);S4023;CA1010;S3442;CA1064;SA1649;SA1625;SA1623;SA1118 $(NoWarn);S3253;S3971;S6605;CA1724;CA1716;SA1108;CA1710;S4049;S3246 - $(NoWarn);CA1805;CA1821 + $(NoWarn);CA1805 $(NoWarn);RS0037; diff --git a/src/Polly/Utilities/TimedLock.cs b/src/Polly/Utilities/TimedLock.cs index 6c97b9dce01..901135c8af7 100644 --- a/src/Polly/Utilities/TimedLock.cs +++ b/src/Polly/Utilities/TimedLock.cs @@ -68,15 +68,15 @@ public void Dispose() // in order to detect when the object is not freed.) private class Sentinel { +#if NETSTANDARD2_0 ~Sentinel() { // If this finalizer runs, someone somewhere failed to // call Dispose, which means we've failed to leave // a monitor! -#if NETSTANDARD2_0 System.Diagnostics.Debug.Fail("Undisposed lock"); -#endif } +#endif } private readonly Sentinel _leakDetector;