#region Copyright & License Information /* * Copyright 2007-2010 The OpenRA Developers (see AUTHORS) * This file is part of OpenRA, which is free software. It is made * available to you under the terms of the GNU General Public License * as published by the Free Software Foundation. For more information, * see LICENSE. */ #endregion using System.Collections.Generic; namespace OpenRA.FileFormats { public struct Pair { public T First; public U Second; public Pair(T first, U second) { First = first; Second = second; } static IEqualityComparer tc = EqualityComparer.Default; static IEqualityComparer uc = EqualityComparer.Default; public static bool operator ==(Pair a, Pair b) { return tc.Equals(a.First, b.First) && uc.Equals(a.Second, b.Second); } public static bool operator !=(Pair a, Pair b) { return !(a == b); } public override bool Equals(object obj) { if (!(obj is Pair)) return false; return (Pair)obj == this; } public override int GetHashCode() { return First.GetHashCode() ^ Second.GetHashCode(); } public Pair WithFirst(T t) { return new Pair(t, Second); } public Pair WithSecond(U u) { return new Pair(First, u); } public static T AsFirst(Pair p) { return p.First; } public static U AsSecond(Pair p) { return p.Second; } public Pair Swap() { return Pair.New(Second, First); } } public static class Pair { public static Pair New(T t, U u) { return new Pair(t, u); } } }