-
Notifications
You must be signed in to change notification settings - Fork 933
/
Copy pathNullableId.cs
58 lines (49 loc) · 1.33 KB
/
NullableId.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
53
54
55
56
57
58
using System;
namespace NHibernate.Test.CompositeId
{
public class NullableId : IComparable<NullableId>
{
public int? Id { get; set; }
public int WarehouseId { get; set; }
public NullableId() { }
public NullableId(int? id, int warehouseId)
{
Id = id;
WarehouseId = warehouseId;
}
public override string ToString() => Id + "|" + WarehouseId;
protected bool Equals(NullableId other) => Id == other.Id && WarehouseId == other.WarehouseId;
public static bool operator ==(NullableId left, NullableId right) => Equals(left, right);
public static bool operator !=(NullableId left, NullableId right) => !Equals(left, right);
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj) || obj.GetType() != this.GetType())
{
return false;
}
return ReferenceEquals(this, obj) || Equals((NullableId)obj);
}
public override int GetHashCode() => HashCode.Combine(Id, WarehouseId);
public int CompareTo(NullableId other)
{
if (ReferenceEquals(this, other))
{
return 0;
}
else if (ReferenceEquals(other, null) || !other.Id.HasValue)
{
return 1;
}
else if (!Id.HasValue)
{
return -1;
}
var idComparison = Id.Value.CompareTo(other.Id);
if (idComparison != 0)
{
return idComparison;
}
return WarehouseId.CompareTo(other.WarehouseId);
}
}
}