CP-36392: Add readonly to fields used in GetHashCode

Also tidy up some code

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>
This commit is contained in:
Danilo Del Busso 2021-10-05 11:33:53 +01:00
parent 36b815f104
commit 3a69fa0f8c
No known key found for this signature in database
GPG Key ID: 0C48542619080FD4
6 changed files with 18 additions and 20 deletions

View File

@ -37,7 +37,7 @@ namespace XenAdmin
{
internal Grouping Grouping;
internal object Parent;
internal object Group;
internal readonly object Group;
/// <summary></summary>
/// <param name="grouping"></param>
@ -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()

View File

@ -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;

View File

@ -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())
{

View File

@ -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);
}
/// <summary>
@ -294,29 +294,28 @@ namespace XenAdmin.XenSearch
public class GroupKey : IEquatable<GroupKey>
{
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;

View File

@ -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)
{

View File

@ -37,7 +37,7 @@ namespace XenAdmin.XenSearch
{
public class QueryScope: IEquatable<QueryScope>
{
private ObjectTypes types;
private readonly ObjectTypes types;
public QueryScope(ObjectTypes types)
{