forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTuple.cs
57 lines (47 loc) · 1.2 KB
/
Tuple.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
using System;
using System.Linq;
using System.Reflection;
namespace NHibernate.Linq.NestedSelects
{
internal class Tuple : IEquatable<Tuple>
{
public static readonly ConstructorInfo Constructor = typeof (Tuple).GetConstructor(new[] { typeof (object[]) });
public static readonly PropertyInfo ItemsProperty = typeof (Tuple).GetProperty("Items");
private readonly object[] _items;
public Tuple(object[] items)
{
if (items == null) throw new ArgumentNullException("items");
_items = items;
}
public object[] Items
{
get { return _items; }
}
public bool Equals(Tuple other)
{
if (other == null) return false;
if (ReferenceEquals(this, other)) return true;
if (other._items.Length != _items.Length)
return false;
return _items.SequenceEqual(other._items);
}
public override bool Equals(object obj)
{
return Equals(obj as Tuple);
}
public override int GetHashCode()
{
unchecked
{
var length = _items.Length;
if (length == 0)
return 0;
var lengthCode = length;
var firstElement = _items[0];
if (ReferenceEquals(firstElement, null))
return lengthCode;
return firstElement.GetHashCode() * 397 ^ lengthCode;
}
}
}
}