From 3a69fa0f8cce99fbc7517731c5812a38e87268a3 Mon Sep 17 00:00:00 2001 From: Danilo Del Busso Date: Tue, 5 Oct 2021 11:33:53 +0100 Subject: [PATCH] CP-36392: Add `readonly` to fields used in `GetHashCode` Also tidy up some code Signed-off-by: Danilo Del Busso --- XenAdmin/GroupingTag.cs | 5 ++--- .../DRWizards/DRFailoverWizardPrecheckPage.cs | 4 ++-- .../PatchingWizard_PrecheckPage.cs | 4 ++-- XenModel/XenSearch/GroupAlg.cs | 19 +++++++++---------- XenModel/XenSearch/Query.cs | 4 ++-- XenModel/XenSearch/QueryScope.cs | 2 +- 6 files changed, 18 insertions(+), 20 deletions(-) diff --git a/XenAdmin/GroupingTag.cs b/XenAdmin/GroupingTag.cs index f7866490b..5bb67ac11 100644 --- a/XenAdmin/GroupingTag.cs +++ b/XenAdmin/GroupingTag.cs @@ -37,7 +37,7 @@ namespace XenAdmin { internal Grouping Grouping; internal object Parent; - internal object Group; + internal readonly object Group; /// /// @@ -55,8 +55,7 @@ namespace XenAdmin public override bool Equals(object obj) { - GroupingTag other = obj as GroupingTag; - return other != null && Grouping.Equals(other.Grouping) && Group.Equals(other.Group); + return obj is GroupingTag other && Grouping.Equals(other.Grouping) && Group.Equals(other.Group); } public override int GetHashCode() diff --git a/XenAdmin/Wizards/DRWizards/DRFailoverWizardPrecheckPage.cs b/XenAdmin/Wizards/DRWizards/DRFailoverWizardPrecheckPage.cs index d941c2694..f126922d0 100644 --- a/XenAdmin/Wizards/DRWizards/DRFailoverWizardPrecheckPage.cs +++ b/XenAdmin/Wizards/DRWizards/DRFailoverWizardPrecheckPage.cs @@ -596,8 +596,8 @@ namespace XenAdmin.Wizards.DRWizards private class PreCheckItemRow : PreCheckGridRow { - private Problem _problem = null; - private Check _check = null; + private readonly Problem _problem; + private readonly Check _check; public PreCheckItemRow(Problem problem) { _problem = problem; diff --git a/XenAdmin/Wizards/PatchingWizard/PatchingWizard_PrecheckPage.cs b/XenAdmin/Wizards/PatchingWizard/PatchingWizard_PrecheckPage.cs index 2dea4c414..b7e968c54 100644 --- a/XenAdmin/Wizards/PatchingWizard/PatchingWizard_PrecheckPage.cs +++ b/XenAdmin/Wizards/PatchingWizard/PatchingWizard_PrecheckPage.cs @@ -611,8 +611,8 @@ namespace XenAdmin.Wizards.PatchingWizard private class PreCheckHostRow : PreCheckGridRow { - private Problem _problem = null; - private Check _check = null; + private readonly Problem _problem = null; + private readonly Check _check = null; public PreCheckHostRow(Problem problem) : base(new DataGridViewTextBoxCell()) { diff --git a/XenModel/XenSearch/GroupAlg.cs b/XenModel/XenSearch/GroupAlg.cs index 4e6ac63c0..65ce7cede 100644 --- a/XenModel/XenSearch/GroupAlg.cs +++ b/XenModel/XenSearch/GroupAlg.cs @@ -167,7 +167,7 @@ namespace XenAdmin.XenSearch return -1; if (other == null) return 1; - return Compare(one.key, other.key); + return Compare(one.Key, other.Key); } /// @@ -294,29 +294,28 @@ namespace XenAdmin.XenSearch public class GroupKey : IEquatable { - public Grouping grouping; - public object key; + public readonly Grouping Grouping; + public readonly object Key; public GroupKey(Grouping grouping, object key) { - this.grouping = grouping; - this.key = key; + Grouping = grouping; + Key = key; } public override int GetHashCode() { - return key.GetHashCode(); + return Key.GetHashCode(); } public bool Equals(GroupKey other) { - return other != null && grouping.Equals(other.grouping) && key.Equals(other.key); + return other != null && Grouping.Equals(other.Grouping) && Key.Equals(other.Key); } public override bool Equals(object obj) { - GroupKey other = obj as GroupKey; - return other != null && Equals(other); + return obj is GroupKey other && Equals(other); } } @@ -350,7 +349,7 @@ namespace XenAdmin.XenSearch foreach (GroupKey group in groups) { - IAcceptGroups subAdapter = adapter.Add(group.grouping, group.key, indent); + IAcceptGroups subAdapter = adapter.Add(group.Grouping, group.Key, indent); if (subAdapter == null) continue; diff --git a/XenModel/XenSearch/Query.cs b/XenModel/XenSearch/Query.cs index 49163729d..04f01c177 100644 --- a/XenModel/XenSearch/Query.cs +++ b/XenModel/XenSearch/Query.cs @@ -36,8 +36,8 @@ namespace XenAdmin.XenSearch { public class Query { - private QueryScope scope; - private QueryFilter filter; + private readonly QueryScope scope; + private readonly QueryFilter filter; public Query(QueryScope scope, QueryFilter filter) { diff --git a/XenModel/XenSearch/QueryScope.cs b/XenModel/XenSearch/QueryScope.cs index dd9da3cd2..6443c2803 100644 --- a/XenModel/XenSearch/QueryScope.cs +++ b/XenModel/XenSearch/QueryScope.cs @@ -37,7 +37,7 @@ namespace XenAdmin.XenSearch { public class QueryScope: IEquatable { - private ObjectTypes types; + private readonly ObjectTypes types; public QueryScope(ObjectTypes types) {