1 //---------------------------------------------------------------------
2 // <copyright file="Pair.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
7 // @backupOwner Microsoft
8 //---------------------------------------------------------------------
11 using System.Collections;
12 using System.Collections.Generic;
14 using System.Diagnostics;
18 namespace System.Data.Common.Utils
20 internal class Pair<TFirst, TSecond> : InternalBase
23 private readonly TFirst first;
24 private readonly TSecond second;
29 internal Pair(TFirst first, TSecond second)
45 internal TSecond Second
55 public override int GetHashCode()
57 return (first.GetHashCode()<<5) ^ second.GetHashCode();
60 public bool Equals(Pair<TFirst, TSecond> other)
62 return first.Equals(other.first) && second.Equals(other.second);
65 public override bool Equals(object other)
67 Pair<TFirst, TSecond> otherPair = other as Pair<TFirst, TSecond>;
69 return (otherPair != null && Equals(otherPair));
74 internal override void ToCompactString(StringBuilder builder)
77 builder.Append(first.ToString());
78 builder.Append(", "+second.ToString());
84 internal class PairComparer : IEqualityComparer<Pair<TFirst, TSecond>>
86 private PairComparer() { }
88 internal static readonly PairComparer Instance = new PairComparer();
89 private static readonly EqualityComparer<TFirst> firstComparer = EqualityComparer<TFirst>.Default;
90 private static readonly EqualityComparer<TSecond> secondComparer = EqualityComparer<TSecond>.Default;
92 public bool Equals(Pair<TFirst, TSecond> x, Pair<TFirst, TSecond> y)
94 return firstComparer.Equals(x.First, y.First) && secondComparer.Equals(x.Second, y.Second);
97 public int GetHashCode(Pair<TFirst, TSecond> source)
99 return source.GetHashCode();