-
Notifications
You must be signed in to change notification settings - Fork 5
/
Group.cs
52 lines (41 loc) · 1.58 KB
/
Group.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Serialization;
namespace Uconomy_Essentials
{
[XmlRoot("UconomyEConfiguration")]
public class Group
{
[XmlAttribute]
public string DisplayName { get; set;}
[XmlAttribute]
public decimal Salary { get; set; }
}
class GroupComparer : IEqualityComparer<Group>
{
public bool Equals(Group x, Group y)
{
//Check whether the compared objects reference the same data.
if (Object.ReferenceEquals(x, y)) return true;
//Check whether any of the compared objects is null.
if (Object.ReferenceEquals(x, null) || Object.ReferenceEquals(y, null))
return false;
//Check whether the products' properties are equal.
return x.DisplayName == y.DisplayName && x.Salary == y.Salary;
}
// If Equals() returns true for a pair of objects
// then GetHashCode() must return the same value for these objects.
public int GetHashCode(Group g)
{
//Check whether the object is null
if (Object.ReferenceEquals(g, null)) return 0;
//Get hash code for the Name field if it is not null.
int hashGroupName = g.DisplayName == null ? 0 : g.DisplayName.GetHashCode();
//Get hash code for the Salary field.
int hashGroupSalary = g.Salary.GetHashCode();
//Calculate the hash code for the product.
return hashGroupName ^ hashGroupSalary;
}
}
}