From f8ff54125f1b143ad1d0b5b9ed51324bab4354db Mon Sep 17 00:00:00 2001 From: James A Sutherland Date: Mon, 13 Jan 2025 12:11:28 -0600 Subject: [PATCH 1/2] Remove Equ more cleanly --- Directory.Packages.props | 1 - IsIdentifiable.sln | 1 + IsIdentifiable/Failures/Failure.cs | 3 +-- IsIdentifiable/Failures/FailurePart.cs | 4 +--- IsIdentifiable/IsIdentifiable.csproj | 1 - IsIdentifiable/Rules/AllowListRule.cs | 11 ++++++++++- IsIdentifiable/Rules/RegexRule.cs | 16 ++++++++++++---- 7 files changed, 25 insertions(+), 12 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index b6568202..72754c82 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -8,7 +8,6 @@ - diff --git a/IsIdentifiable.sln b/IsIdentifiable.sln index 4cabe2fc..51897531 100644 --- a/IsIdentifiable.sln +++ b/IsIdentifiable.sln @@ -14,6 +14,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution .editorconfig = .editorconfig CHANGELOG.md = CHANGELOG.md Directory.Build.props = Directory.Build.props + Directory.Packages.props = Directory.Packages.props .github\workflows\dotnet-core.yml = .github\workflows\dotnet-core.yml PACKAGES.md = PACKAGES.md README.md = README.md diff --git a/IsIdentifiable/Failures/Failure.cs b/IsIdentifiable/Failures/Failure.cs index 888380d2..5fa991f0 100644 --- a/IsIdentifiable/Failures/Failure.cs +++ b/IsIdentifiable/Failures/Failure.cs @@ -1,4 +1,3 @@ -using Equ; using System; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -12,7 +11,7 @@ namespace IsIdentifiable.Failures; /// along with the (if any) so that the row on which /// the data was found can located (e.g. to perform redaction). /// -public class Failure : MemberwiseEquatable +public record Failure { /// /// Each sub part of that the system had a problem with diff --git a/IsIdentifiable/Failures/FailurePart.cs b/IsIdentifiable/Failures/FailurePart.cs index 9e3d14fc..e73ade44 100644 --- a/IsIdentifiable/Failures/FailurePart.cs +++ b/IsIdentifiable/Failures/FailurePart.cs @@ -1,5 +1,3 @@ -using Equ; - namespace IsIdentifiable.Failures; /// @@ -7,7 +5,7 @@ namespace IsIdentifiable.Failures; /// A can have multiple e.g. if it is free text with multiple failing /// words. /// -public class FailurePart : MemberwiseEquatable +public record FailurePart { /// /// The classification of the failure e.g. CHI, PERSON, TextInPixel diff --git a/IsIdentifiable/IsIdentifiable.csproj b/IsIdentifiable/IsIdentifiable.csproj index ae94c356..8725b0ec 100644 --- a/IsIdentifiable/IsIdentifiable.csproj +++ b/IsIdentifiable/IsIdentifiable.csproj @@ -24,7 +24,6 @@ - diff --git a/IsIdentifiable/Rules/AllowListRule.cs b/IsIdentifiable/Rules/AllowListRule.cs index 4f35036a..470f021c 100644 --- a/IsIdentifiable/Rules/AllowListRule.cs +++ b/IsIdentifiable/Rules/AllowListRule.cs @@ -14,8 +14,17 @@ namespace IsIdentifiable.Rules; /// /// Expanded which works only for . Should be run after main rules have picked up failures. This class is designed to perform final checks on failures and discard based on and/or /// -public class AllowlistRule : RegexRule +public record AllowlistRule : RegexRule { + /// + public virtual bool Equals(AllowlistRule? other) + { + if (other is null) return false; + if (ReferenceEquals(this, other)) return true; + return base.Equals(other) && _ifPartPatternString == other._ifPartPatternString; + } + + public override int GetHashCode() => HashCode.Combine(base.GetHashCode(), _ifPartPatternString); /// /// Combination of and . Use this to validate diff --git a/IsIdentifiable/Rules/RegexRule.cs b/IsIdentifiable/Rules/RegexRule.cs index 3e75dfe5..e82e9879 100644 --- a/IsIdentifiable/Rules/RegexRule.cs +++ b/IsIdentifiable/Rules/RegexRule.cs @@ -1,7 +1,5 @@ -using Equ; using IsIdentifiable.Failures; using System; -using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; @@ -17,8 +15,18 @@ namespace IsIdentifiable.Rules; /// A simple Regex based rule that allows flexible white listing or blacklisting of values /// either in all columns or only a single column /// -public class RegexRule : MemberwiseEquatable, IRegexRule +public record RegexRule : IRegexRule { + /// + public virtual bool Equals(RegexRule? other) + { + if (other is null) return false; + if (ReferenceEquals(this, other)) return true; + return _ifPatternString == other._ifPatternString && _caseSensitive == other._caseSensitive && Action == other.Action && IfColumn == other.IfColumn && As == other.As; + } + + public override int GetHashCode() => HashCode.Combine(_ifPatternString, _caseSensitive, (int)Action, IfColumn, (int)As); + /// public RuleAction Action { get; set; } @@ -32,7 +40,7 @@ public class RegexRule : MemberwiseEquatable, IRegexRule /// Combination of and . Use this to validate /// whether the rule should be applied. /// - [MemberwiseEqualityIgnore] // NOTE(rkm 2023-05-03) Exclude so equality comparer is valid + // [MemberwiseEqualityIgnore] // NOTE(rkm 2023-05-03) Exclude so equality comparer is valid - JAS 2025-01-13 moved to explicit Equals instead of Equ protected Regex? IfPatternRegex; private string? _ifPatternString; From ad077999a4067ee61e362566052960ef9f0e510c Mon Sep 17 00:00:00 2001 From: James A Sutherland <> Date: Mon, 13 Jan 2025 14:25:00 -0600 Subject: [PATCH 2/2] Remove Equ entry from PACKAGES.md --- PACKAGES.md | 1 - 1 file changed, 1 deletion(-) diff --git a/PACKAGES.md b/PACKAGES.md index 4178be3e..ea9fe4f4 100644 --- a/PACKAGES.md +++ b/PACKAGES.md @@ -8,7 +8,6 @@ | Package | Source Code | License | Purpose | | --------------------------------------- | -------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | -| [Equ](https://github.com/thedmi/Equ) | [GitHub](https://github.com/thedmi/Equ) | [MIT](https://opensource.org/licenses/MIT) | Simplifies object comparators | | [NLog](https://nlog-project.org/) | [GitHub](https://github.com/NLog/NLog) | [BSD 3-Clause](https://github.com/NLog/NLog/blob/dev/LICENSE.txt) | Flexible user configurable logging | | [Nunit](https://nunit.org/) | [GitHub](https://github.com/nunit/nunit) | [MIT](https://opensource.org/licenses/MIT) | Unit testing | | CommandLineParser | [GitHub](https://github.com/commandlineparser/commandline) | [MIT](https://opensource.org/licenses/MIT) | Allows command line arguments for main client application and CLI executables |