Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ValueTuple`2.cs « Util « CSharpBinding « addins « src « main - github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 96fcb2eb4b1ac95544e7cdb4d51024b14ab73ffd (plain)
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
// Copyright (c) Microsoft.  All Rights Reserved.  Licensed under the Apache License, Version 2.0.  See License.txt in the project root for license information.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;

namespace ICSharpCode.NRefactory6.CSharp
{
	// struct with two values
	struct ValueTuple<T1, T2> : IEquatable<ValueTuple<T1, T2>>
	{
		private static readonly EqualityComparer<T1> s_comparer1 = EqualityComparer<T1>.Default;
		private static readonly EqualityComparer<T2> s_comparer2 = EqualityComparer<T2>.Default;

		public readonly T1 Item1;
		public readonly T2 Item2;

		public ValueTuple(T1 item1, T2 item2)
		{
			this.Item1 = item1;
			this.Item2 = item2;
		}

		public bool Equals(ValueTuple<T1, T2> other)
		{
			return s_comparer1.Equals(this.Item1, other.Item1)
				&& s_comparer2.Equals(this.Item2, other.Item2);
		}

		public override bool Equals(object obj)
		{
			if (obj is ValueTuple<T1, T2>)
			{
				var other = (ValueTuple<T1, T2>)obj;
				return this.Equals(other);
			}

			return false;
		}

		public override int GetHashCode()
		{
			return Hash.Combine(s_comparer1.GetHashCode(Item1), s_comparer2.GetHashCode(Item2));
		}

		public static bool operator ==(ValueTuple<T1, T2> left, ValueTuple<T1, T2> right)
		{
			return left.Equals(right);
		}

		public static bool operator !=(ValueTuple<T1, T2> left, ValueTuple<T1, T2> right)
		{
			return !left.Equals(right);
		}
	}
}