forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMutableHashCode.cs
44 lines (38 loc) · 1.08 KB
/
MutableHashCode.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
using System;
namespace NHibernate.Test.UtilityTest
{
/// <summary>
/// Provides an object whose HashCode is based on a Mutable field. Not a good
/// practice but perfect for testing IdentityMap because it simulates an object
/// being loaded with its default constructor (no params) and then having the
/// fields initialized. If the class overrides GetHashCode() then it will be inconsistent
/// between the construction and field population by NHibernate.
/// </summary>
[Serializable]
public class MutableHashCode
{
private int hashCodeField;
public MutableHashCode()
{
}
public MutableHashCode(int hashCodeField)
{
this.hashCodeField = hashCodeField;
}
public int HashCodeField
{
get { return hashCodeField; }
set { hashCodeField = value; }
}
public override int GetHashCode()
{
return hashCodeField.GetHashCode();
}
public override bool Equals(object obj)
{
// I am not putting all of the proper comparisons in here
// because this is just simple test code.
return hashCodeField.Equals(((MutableHashCode) obj).HashCodeField);
}
}
}