1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195 |
- // defined from .NET Framework 4.0 and NETFX_CORE
- // This code is basaed from mono/mcs, but some performance modified
- // 1. class to struct
- // 2. implements IEquatable<T1, T2,...>
- // note, we need to create ValueTuple or UniRxTuple...
- #if !(NETFX_CORE || NET_4_6 || NET_STANDARD_2_0 || UNITY_WSA_10_0)
- using System;
- using System.Collections;
- using System.Collections.Generic;
- namespace UniRx
- {
- public interface IStructuralEquatable
- {
- bool Equals(object other, IEqualityComparer comparer);
- int GetHashCode(IEqualityComparer comparer);
- }
- public interface IStructuralComparable
- {
- int CompareTo(object other, IComparer comparer);
- }
- interface ITuple
- {
- string ToString();
- }
- public static class Tuple
- {
- public static Tuple<T1, T2, T3, T4, T5, T6, T7, Tuple<T8>> Create<T1, T2, T3, T4, T5, T6, T7, T8>
- (
- T1 item1,
- T2 item2,
- T3 item3,
- T4 item4,
- T5 item5,
- T6 item6,
- T7 item7,
- T8 item8)
- {
- return new Tuple<T1, T2, T3, T4, T5, T6, T7, Tuple<T8>>(item1, item2, item3, item4, item5, item6, item7, new Tuple<T8>(item8));
- }
- public static Tuple<T1, T2, T3, T4, T5, T6, T7> Create<T1, T2, T3, T4, T5, T6, T7>
- (
- T1 item1,
- T2 item2,
- T3 item3,
- T4 item4,
- T5 item5,
- T6 item6,
- T7 item7)
- {
- return new Tuple<T1, T2, T3, T4, T5, T6, T7>(item1, item2, item3, item4, item5, item6, item7);
- }
- public static Tuple<T1, T2, T3, T4, T5, T6> Create<T1, T2, T3, T4, T5, T6>
- (
- T1 item1,
- T2 item2,
- T3 item3,
- T4 item4,
- T5 item5,
- T6 item6)
- {
- return new Tuple<T1, T2, T3, T4, T5, T6>(item1, item2, item3, item4, item5, item6);
- }
- public static Tuple<T1, T2, T3, T4, T5> Create<T1, T2, T3, T4, T5>
- (
- T1 item1,
- T2 item2,
- T3 item3,
- T4 item4,
- T5 item5)
- {
- return new Tuple<T1, T2, T3, T4, T5>(item1, item2, item3, item4, item5);
- }
- public static Tuple<T1, T2, T3, T4> Create<T1, T2, T3, T4>
- (
- T1 item1,
- T2 item2,
- T3 item3,
- T4 item4)
- {
- return new Tuple<T1, T2, T3, T4>(item1, item2, item3, item4);
- }
- public static Tuple<T1, T2, T3> Create<T1, T2, T3>
- (
- T1 item1,
- T2 item2,
- T3 item3)
- {
- return new Tuple<T1, T2, T3>(item1, item2, item3);
- }
- public static Tuple<T1, T2> Create<T1, T2>
- (
- T1 item1,
- T2 item2)
- {
- return new Tuple<T1, T2>(item1, item2);
- }
- public static Tuple<T1> Create<T1>
- (
- T1 item1)
- {
- return new Tuple<T1>(item1);
- }
- }
- public partial class Tuple<T1, T2, T3, T4, T5, T6, T7, TRest>
- {
- public Tuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7, TRest rest)
- {
- this.item1 = item1;
- this.item2 = item2;
- this.item3 = item3;
- this.item4 = item4;
- this.item5 = item5;
- this.item6 = item6;
- this.item7 = item7;
- this.rest = rest;
- if (!(rest is ITuple))
- throw new ArgumentException("rest", "The last element of an eight element tuple must be a Tuple.");
- }
- }
- [Serializable]
- public struct Tuple<T1> : IStructuralEquatable, IStructuralComparable, IComparable, ITuple, IEquatable<Tuple<T1>>
- {
- T1 item1;
- public Tuple(T1 item1)
- {
- this.item1 = item1;
- }
- public T1 Item1
- {
- get { return item1; }
- }
- int IComparable.CompareTo(object obj)
- {
- return ((IStructuralComparable)this).CompareTo(obj, Comparer<object>.Default);
- }
- int IStructuralComparable.CompareTo(object other, IComparer comparer)
- {
- if (other == null) return 1;
- if (!(other is Tuple<T1>))
- {
- throw new ArgumentException("other");
- }
- var t = (Tuple<T1>)other;
- return comparer.Compare(item1, t.item1);
- }
- public override bool Equals(object obj)
- {
- return ((IStructuralEquatable)this).Equals(obj, EqualityComparer<object>.Default);
- }
- bool IStructuralEquatable.Equals(object other, IEqualityComparer comparer)
- {
- if (!(other is Tuple<T1>))
- return false;
- var t = (Tuple<T1>)other;
- return comparer.Equals(item1, t.item1);
- }
- public override int GetHashCode()
- {
- return EqualityComparer<T1>.Default.GetHashCode(item1);
- }
- int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
- {
- return comparer.GetHashCode(item1);
- }
- string ITuple.ToString()
- {
- return String.Format("{0}", item1);
- }
- public override string ToString()
- {
- return "(" + ((ITuple)this).ToString() + ")";
- }
- public bool Equals(Tuple<T1> other)
- {
- return EqualityComparer<T1>.Default.Equals(item1, other.item1);
- }
- }
- [Serializable]
- public struct Tuple<T1, T2> : IStructuralEquatable, IStructuralComparable, IComparable, ITuple, IEquatable<Tuple<T1, T2>>
- {
- T1 item1;
- T2 item2;
- public Tuple(T1 item1, T2 item2)
- {
- this.item1 = item1;
- this.item2 = item2;
- }
- public T1 Item1
- {
- get { return item1; }
- }
- public T2 Item2
- {
- get { return item2; }
- }
- int IComparable.CompareTo(object obj)
- {
- return ((IStructuralComparable)this).CompareTo(obj, Comparer<object>.Default);
- }
- int IStructuralComparable.CompareTo(object other, IComparer comparer)
- {
- if (other == null) return 1;
- if (!(other is Tuple<T1, T2>))
- {
- throw new ArgumentException("other");
- }
- var t = (Tuple<T1, T2>)other;
- int res = comparer.Compare(item1, t.item1);
- if (res != 0) return res;
- return comparer.Compare(item2, t.item2);
- }
- public override bool Equals(object obj)
- {
- return ((IStructuralEquatable)this).Equals(obj, EqualityComparer<object>.Default);
- }
- bool IStructuralEquatable.Equals(object other, IEqualityComparer comparer)
- {
- if (!(other is Tuple<T1, T2>))
- return false;
- var t = (Tuple<T1, T2>)other;
- return comparer.Equals(item1, t.item1) &&
- comparer.Equals(item2, t.item2);
- }
- public override int GetHashCode()
- {
- var comparer1 = EqualityComparer<T1>.Default;
- var comparer2 = EqualityComparer<T2>.Default;
- int h0;
- h0 = comparer1.GetHashCode(item1);
- h0 = (h0 << 5) + h0 ^ comparer2.GetHashCode(item2);
- return h0;
- }
- int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
- {
- int h0;
- h0 = comparer.GetHashCode(item1);
- h0 = (h0 << 5) + h0 ^ comparer.GetHashCode(item2);
- return h0;
- }
- string ITuple.ToString()
- {
- return String.Format("{0}, {1}", item1, item2);
- }
- public override string ToString()
- {
- return "(" + ((ITuple)this).ToString() + ")";
- }
- public bool Equals(Tuple<T1, T2> other)
- {
- var comparer1 = EqualityComparer<T1>.Default;
- var comparer2 = EqualityComparer<T2>.Default;
- return comparer1.Equals(item1, other.item1) &&
- comparer2.Equals(item2, other.item2);
- }
- }
- [Serializable]
- public struct Tuple<T1, T2, T3> : IStructuralEquatable, IStructuralComparable, IComparable, ITuple, IEquatable<Tuple<T1, T2, T3>>
- {
- T1 item1;
- T2 item2;
- T3 item3;
- public Tuple(T1 item1, T2 item2, T3 item3)
- {
- this.item1 = item1;
- this.item2 = item2;
- this.item3 = item3;
- }
- public T1 Item1
- {
- get { return item1; }
- }
- public T2 Item2
- {
- get { return item2; }
- }
- public T3 Item3
- {
- get { return item3; }
- }
- int IComparable.CompareTo(object obj)
- {
- return ((IStructuralComparable)this).CompareTo(obj, Comparer<object>.Default);
- }
- int IStructuralComparable.CompareTo(object other, IComparer comparer)
- {
- if (other == null) return 1;
- if (!(other is Tuple<T1, T2, T3>))
- {
- throw new ArgumentException("other");
- }
- var t = (Tuple<T1, T2, T3>)other;
- int res = comparer.Compare(item1, t.item1);
- if (res != 0) return res;
- res = comparer.Compare(item2, t.item2);
- if (res != 0) return res;
- return comparer.Compare(item3, t.item3);
- }
- public override bool Equals(object obj)
- {
- return ((IStructuralEquatable)this).Equals(obj, EqualityComparer<object>.Default);
- }
- bool IStructuralEquatable.Equals(object other, IEqualityComparer comparer)
- {
- if (!(other is Tuple<T1, T2, T3>))
- return false;
- var t = (Tuple<T1, T2, T3>)other;
- return comparer.Equals(item1, t.item1) &&
- comparer.Equals(item2, t.item2) &&
- comparer.Equals(item3, t.item3);
- }
- public override int GetHashCode()
- {
- var comparer1 = EqualityComparer<T1>.Default;
- var comparer2 = EqualityComparer<T2>.Default;
- var comparer3 = EqualityComparer<T3>.Default;
- int h0;
- h0 = comparer1.GetHashCode(item1);
- h0 = (h0 << 5) + h0 ^ comparer2.GetHashCode(item2);
- h0 = (h0 << 5) + h0 ^ comparer3.GetHashCode(item3);
- return h0;
- }
- int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
- {
- int h0;
- h0 = comparer.GetHashCode(item1);
- h0 = (h0 << 5) + h0 ^ comparer.GetHashCode(item2);
- h0 = (h0 << 5) + h0 ^ comparer.GetHashCode(item3);
- return h0;
- }
- string ITuple.ToString()
- {
- return String.Format("{0}, {1}, {2}", item1, item2, item3);
- }
- public override string ToString()
- {
- return "(" + ((ITuple)this).ToString() + ")";
- }
- public bool Equals(Tuple<T1, T2, T3> other)
- {
- var comparer1 = EqualityComparer<T1>.Default;
- var comparer2 = EqualityComparer<T2>.Default;
- var comparer3 = EqualityComparer<T3>.Default;
- return comparer1.Equals(item1, other.item1) &&
- comparer2.Equals(item2, other.item2) &&
- comparer3.Equals(item3, other.item3);
- }
- }
- [Serializable]
- public struct Tuple<T1, T2, T3, T4> : IStructuralEquatable, IStructuralComparable, IComparable, ITuple, IEquatable<Tuple<T1, T2, T3, T4>>
- {
- T1 item1;
- T2 item2;
- T3 item3;
- T4 item4;
- public Tuple(T1 item1, T2 item2, T3 item3, T4 item4)
- {
- this.item1 = item1;
- this.item2 = item2;
- this.item3 = item3;
- this.item4 = item4;
- }
- public T1 Item1
- {
- get { return item1; }
- }
- public T2 Item2
- {
- get { return item2; }
- }
- public T3 Item3
- {
- get { return item3; }
- }
- public T4 Item4
- {
- get { return item4; }
- }
- int IComparable.CompareTo(object obj)
- {
- return ((IStructuralComparable)this).CompareTo(obj, Comparer<object>.Default);
- }
- int IStructuralComparable.CompareTo(object other, IComparer comparer)
- {
- if (other == null) return 1;
- if (!(other is Tuple<T1, T2, T3, T4>))
- {
- throw new ArgumentException("other");
- }
- var t = (Tuple<T1, T2, T3, T4>)other;
- int res = comparer.Compare(item1, t.item1);
- if (res != 0) return res;
- res = comparer.Compare(item2, t.item2);
- if (res != 0) return res;
- res = comparer.Compare(item3, t.item3);
- if (res != 0) return res;
- return comparer.Compare(item4, t.item4);
- }
- public override bool Equals(object obj)
- {
- return ((IStructuralEquatable)this).Equals(obj, EqualityComparer<object>.Default);
- }
- bool IStructuralEquatable.Equals(object other, IEqualityComparer comparer)
- {
- if (!(other is Tuple<T1, T2, T3, T4>))
- return false;
- var t = (Tuple<T1, T2, T3, T4>)other;
- return comparer.Equals(item1, t.item1) &&
- comparer.Equals(item2, t.item2) &&
- comparer.Equals(item3, t.item3) &&
- comparer.Equals(item4, t.item4);
- }
- public override int GetHashCode()
- {
- var comparer1 = EqualityComparer<T1>.Default;
- var comparer2 = EqualityComparer<T2>.Default;
- var comparer3 = EqualityComparer<T3>.Default;
- var comparer4 = EqualityComparer<T4>.Default;
- int h0, h1;
- h0 = comparer1.GetHashCode(item1);
- h0 = (h0 << 5) + h0 ^ comparer2.GetHashCode(item2);
- h1 = comparer3.GetHashCode(item3);
- h1 = (h1 << 5) + h1 ^ comparer4.GetHashCode(item4);
- h0 = (h0 << 5) + h0 ^ h1;
- return h0;
- }
- int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
- {
- int h0, h1;
- h0 = comparer.GetHashCode(item1);
- h0 = (h0 << 5) + h0 ^ comparer.GetHashCode(item2);
- h1 = comparer.GetHashCode(item3);
- h1 = (h1 << 5) + h1 ^ comparer.GetHashCode(item4);
- h0 = (h0 << 5) + h0 ^ h1;
- return h0;
- }
- string ITuple.ToString()
- {
- return String.Format("{0}, {1}, {2}, {3}", item1, item2, item3, item4);
- }
- public override string ToString()
- {
- return "(" + ((ITuple)this).ToString() + ")";
- }
- public bool Equals(Tuple<T1, T2, T3, T4> other)
- {
- var comparer1 = EqualityComparer<T1>.Default;
- var comparer2 = EqualityComparer<T2>.Default;
- var comparer3 = EqualityComparer<T3>.Default;
- var comparer4 = EqualityComparer<T4>.Default;
- return comparer1.Equals(item1, other.item1) &&
- comparer2.Equals(item2, other.item2) &&
- comparer3.Equals(item3, other.item3) &&
- comparer4.Equals(item4, other.item4);
- }
- }
- [Serializable]
- public struct Tuple<T1, T2, T3, T4, T5> : IStructuralEquatable, IStructuralComparable, IComparable, ITuple, IEquatable<Tuple<T1, T2, T3, T4, T5>>
- {
- T1 item1;
- T2 item2;
- T3 item3;
- T4 item4;
- T5 item5;
- public Tuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5)
- {
- this.item1 = item1;
- this.item2 = item2;
- this.item3 = item3;
- this.item4 = item4;
- this.item5 = item5;
- }
- public T1 Item1
- {
- get { return item1; }
- }
- public T2 Item2
- {
- get { return item2; }
- }
- public T3 Item3
- {
- get { return item3; }
- }
- public T4 Item4
- {
- get { return item4; }
- }
- public T5 Item5
- {
- get { return item5; }
- }
- int IComparable.CompareTo(object obj)
- {
- return ((IStructuralComparable)this).CompareTo(obj, Comparer<object>.Default);
- }
- int IStructuralComparable.CompareTo(object other, IComparer comparer)
- {
- if (other == null) return 1;
- if (!(other is Tuple<T1, T2, T3, T4, T5>))
- {
- throw new ArgumentException("other");
- }
- var t = (Tuple<T1, T2, T3, T4, T5>)other;
- int res = comparer.Compare(item1, t.item1);
- if (res != 0) return res;
- res = comparer.Compare(item2, t.item2);
- if (res != 0) return res;
- res = comparer.Compare(item3, t.item3);
- if (res != 0) return res;
- res = comparer.Compare(item4, t.item4);
- if (res != 0) return res;
- return comparer.Compare(item5, t.item5);
- }
- public override bool Equals(object obj)
- {
- return ((IStructuralEquatable)this).Equals(obj, EqualityComparer<object>.Default);
- }
- bool IStructuralEquatable.Equals(object other, IEqualityComparer comparer)
- {
- if (!(other is Tuple<T1, T2, T3, T4, T5>))
- return false;
- var t = (Tuple<T1, T2, T3, T4, T5>)other;
- return comparer.Equals(item1, t.item1) &&
- comparer.Equals(item2, t.item2) &&
- comparer.Equals(item3, t.item3) &&
- comparer.Equals(item4, t.item4) &&
- comparer.Equals(item5, t.item5);
- }
- public override int GetHashCode()
- {
- var comparer1 = EqualityComparer<T1>.Default;
- var comparer2 = EqualityComparer<T2>.Default;
- var comparer3 = EqualityComparer<T3>.Default;
- var comparer4 = EqualityComparer<T4>.Default;
- var comparer5 = EqualityComparer<T5>.Default;
- int h0, h1;
- h0 = comparer1.GetHashCode(item1);
- h0 = (h0 << 5) + h0 ^ comparer2.GetHashCode(item2);
- h1 = comparer3.GetHashCode(item3);
- h1 = (h1 << 5) + h1 ^ comparer4.GetHashCode(item4);
- h0 = (h0 << 5) + h0 ^ h1;
- h0 = (h0 << 5) + h0 ^ comparer5.GetHashCode(item5);
- return h0;
- }
- int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
- {
- int h0, h1;
- h0 = comparer.GetHashCode(item1);
- h0 = (h0 << 5) + h0 ^ comparer.GetHashCode(item2);
- h1 = comparer.GetHashCode(item3);
- h1 = (h1 << 5) + h1 ^ comparer.GetHashCode(item4);
- h0 = (h0 << 5) + h0 ^ h1;
- h0 = (h0 << 5) + h0 ^ comparer.GetHashCode(item5);
- return h0;
- }
- string ITuple.ToString()
- {
- return String.Format("{0}, {1}, {2}, {3}, {4}", item1, item2, item3, item4, item5);
- }
- public override string ToString()
- {
- return "(" + ((ITuple)this).ToString() + ")";
- }
- public bool Equals(Tuple<T1, T2, T3, T4, T5> other)
- {
- var comparer1 = EqualityComparer<T1>.Default;
- var comparer2 = EqualityComparer<T2>.Default;
- var comparer3 = EqualityComparer<T3>.Default;
- var comparer4 = EqualityComparer<T4>.Default;
- var comparer5 = EqualityComparer<T5>.Default;
- return comparer1.Equals(item1, other.Item1) &&
- comparer2.Equals(item2, other.Item2) &&
- comparer3.Equals(item3, other.Item3) &&
- comparer4.Equals(item4, other.Item4) &&
- comparer5.Equals(item5, other.Item5);
- }
- }
- [Serializable]
- public struct Tuple<T1, T2, T3, T4, T5, T6> : IStructuralEquatable, IStructuralComparable, IComparable, ITuple, IEquatable<Tuple<T1, T2, T3, T4, T5, T6>>
- {
- T1 item1;
- T2 item2;
- T3 item3;
- T4 item4;
- T5 item5;
- T6 item6;
- public Tuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6)
- {
- this.item1 = item1;
- this.item2 = item2;
- this.item3 = item3;
- this.item4 = item4;
- this.item5 = item5;
- this.item6 = item6;
- }
- public T1 Item1
- {
- get { return item1; }
- }
- public T2 Item2
- {
- get { return item2; }
- }
- public T3 Item3
- {
- get { return item3; }
- }
- public T4 Item4
- {
- get { return item4; }
- }
- public T5 Item5
- {
- get { return item5; }
- }
- public T6 Item6
- {
- get { return item6; }
- }
- int IComparable.CompareTo(object obj)
- {
- return ((IStructuralComparable)this).CompareTo(obj, Comparer<object>.Default);
- }
- int IStructuralComparable.CompareTo(object other, IComparer comparer)
- {
- if (other == null) return 1;
- if (!(other is Tuple<T1, T2, T3, T4, T5, T6>))
- {
- throw new ArgumentException("other");
- }
- var t = (Tuple<T1, T2, T3, T4, T5, T6>)other;
- int res = comparer.Compare(item1, t.item1);
- if (res != 0) return res;
- res = comparer.Compare(item2, t.item2);
- if (res != 0) return res;
- res = comparer.Compare(item3, t.item3);
- if (res != 0) return res;
- res = comparer.Compare(item4, t.item4);
- if (res != 0) return res;
- res = comparer.Compare(item5, t.item5);
- if (res != 0) return res;
- return comparer.Compare(item6, t.item6);
- }
- public override bool Equals(object obj)
- {
- return ((IStructuralEquatable)this).Equals(obj, EqualityComparer<object>.Default);
- }
- bool IStructuralEquatable.Equals(object other, IEqualityComparer comparer)
- {
- if (!(other is Tuple<T1, T2, T3, T4, T5, T6>))
- return false;
- var t = (Tuple<T1, T2, T3, T4, T5, T6>)other;
- return comparer.Equals(item1, t.item1) &&
- comparer.Equals(item2, t.item2) &&
- comparer.Equals(item3, t.item3) &&
- comparer.Equals(item4, t.item4) &&
- comparer.Equals(item5, t.item5) &&
- comparer.Equals(item6, t.item6);
- }
- public override int GetHashCode()
- {
- var comparer1 = EqualityComparer<T1>.Default;
- var comparer2 = EqualityComparer<T2>.Default;
- var comparer3 = EqualityComparer<T3>.Default;
- var comparer4 = EqualityComparer<T4>.Default;
- var comparer5 = EqualityComparer<T5>.Default;
- var comparer6 = EqualityComparer<T6>.Default;
- int h0, h1;
- h0 = comparer1.GetHashCode(item1);
- h0 = (h0 << 5) + h0 ^ comparer2.GetHashCode(item2);
- h1 = comparer3.GetHashCode(item3);
- h1 = (h1 << 5) + h1 ^ comparer4.GetHashCode(item4);
- h0 = (h0 << 5) + h0 ^ h1;
- h1 = comparer5.GetHashCode(item5);
- h1 = (h1 << 5) + h1 ^ comparer6.GetHashCode(item6);
- h0 = (h0 << 5) + h0 ^ h1;
- return h0;
- }
- int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
- {
- int h0, h1;
- h0 = comparer.GetHashCode(item1);
- h0 = (h0 << 5) + h0 ^ comparer.GetHashCode(item2);
- h1 = comparer.GetHashCode(item3);
- h1 = (h1 << 5) + h1 ^ comparer.GetHashCode(item4);
- h0 = (h0 << 5) + h0 ^ h1;
- h1 = comparer.GetHashCode(item5);
- h1 = (h1 << 5) + h1 ^ comparer.GetHashCode(item6);
- h0 = (h0 << 5) + h0 ^ h1;
- return h0;
- }
- string ITuple.ToString()
- {
- return String.Format("{0}, {1}, {2}, {3}, {4}, {5}", item1, item2, item3, item4, item5, item6);
- }
- public override string ToString()
- {
- return "(" + ((ITuple)this).ToString() + ")";
- }
- public bool Equals(Tuple<T1, T2, T3, T4, T5, T6> other)
- {
- var comparer1 = EqualityComparer<T1>.Default;
- var comparer2 = EqualityComparer<T2>.Default;
- var comparer3 = EqualityComparer<T3>.Default;
- var comparer4 = EqualityComparer<T4>.Default;
- var comparer5 = EqualityComparer<T5>.Default;
- var comparer6 = EqualityComparer<T6>.Default;
- return comparer1.Equals(item1, other.Item1) &&
- comparer2.Equals(item2, other.Item2) &&
- comparer3.Equals(item3, other.Item3) &&
- comparer4.Equals(item4, other.Item4) &&
- comparer5.Equals(item5, other.Item5) &&
- comparer6.Equals(item6, other.Item6);
- }
- }
- [Serializable]
- public struct Tuple<T1, T2, T3, T4, T5, T6, T7> : IStructuralEquatable, IStructuralComparable, IComparable, ITuple, IEquatable<Tuple<T1, T2, T3, T4, T5, T6, T7>>
- {
- T1 item1;
- T2 item2;
- T3 item3;
- T4 item4;
- T5 item5;
- T6 item6;
- T7 item7;
- public Tuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7)
- {
- this.item1 = item1;
- this.item2 = item2;
- this.item3 = item3;
- this.item4 = item4;
- this.item5 = item5;
- this.item6 = item6;
- this.item7 = item7;
- }
- public T1 Item1
- {
- get { return item1; }
- }
- public T2 Item2
- {
- get { return item2; }
- }
- public T3 Item3
- {
- get { return item3; }
- }
- public T4 Item4
- {
- get { return item4; }
- }
- public T5 Item5
- {
- get { return item5; }
- }
- public T6 Item6
- {
- get { return item6; }
- }
- public T7 Item7
- {
- get { return item7; }
- }
- int IComparable.CompareTo(object obj)
- {
- return ((IStructuralComparable)this).CompareTo(obj, Comparer<object>.Default);
- }
- int IStructuralComparable.CompareTo(object other, IComparer comparer)
- {
- if (other == null) return 1;
- if (!(other is Tuple<T1, T2, T3, T4, T5, T6, T7>))
- {
- throw new ArgumentException("other");
- }
- var t = (Tuple<T1, T2, T3, T4, T5, T6, T7>)other;
- int res = comparer.Compare(item1, t.item1);
- if (res != 0) return res;
- res = comparer.Compare(item2, t.item2);
- if (res != 0) return res;
- res = comparer.Compare(item3, t.item3);
- if (res != 0) return res;
- res = comparer.Compare(item4, t.item4);
- if (res != 0) return res;
- res = comparer.Compare(item5, t.item5);
- if (res != 0) return res;
- res = comparer.Compare(item6, t.item6);
- if (res != 0) return res;
- return comparer.Compare(item7, t.item7);
- }
- public override bool Equals(object obj)
- {
- return ((IStructuralEquatable)this).Equals(obj, EqualityComparer<object>.Default);
- }
- bool IStructuralEquatable.Equals(object other, IEqualityComparer comparer)
- {
- if (!(other is Tuple<T1, T2, T3, T4, T5, T6, T7>))
- return false;
- var t = (Tuple<T1, T2, T3, T4, T5, T6, T7>)other;
- return comparer.Equals(item1, t.item1) &&
- comparer.Equals(item2, t.item2) &&
- comparer.Equals(item3, t.item3) &&
- comparer.Equals(item4, t.item4) &&
- comparer.Equals(item5, t.item5) &&
- comparer.Equals(item6, t.item6) &&
- comparer.Equals(item7, t.item7);
- }
- public override int GetHashCode()
- {
- var comparer1 = EqualityComparer<T1>.Default;
- var comparer2 = EqualityComparer<T2>.Default;
- var comparer3 = EqualityComparer<T3>.Default;
- var comparer4 = EqualityComparer<T4>.Default;
- var comparer5 = EqualityComparer<T5>.Default;
- var comparer6 = EqualityComparer<T6>.Default;
- var comparer7 = EqualityComparer<T7>.Default;
- int h0, h1;
- h0 = comparer1.GetHashCode(item1);
- h0 = (h0 << 5) + h0 ^ comparer2.GetHashCode(item2);
- h1 = comparer3.GetHashCode(item3);
- h1 = (h1 << 5) + h1 ^ comparer4.GetHashCode(item4);
- h0 = (h0 << 5) + h0 ^ h1;
- h1 = comparer5.GetHashCode(item5);
- h1 = (h1 << 5) + h1 ^ comparer6.GetHashCode(item6);
- h1 = (h1 << 5) + h1 ^ comparer7.GetHashCode(item7);
- h0 = (h0 << 5) + h0 ^ h1;
- return h0;
- }
- int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
- {
- int h0, h1;
- h0 = comparer.GetHashCode(item1);
- h0 = (h0 << 5) + h0 ^ comparer.GetHashCode(item2);
- h1 = comparer.GetHashCode(item3);
- h1 = (h1 << 5) + h1 ^ comparer.GetHashCode(item4);
- h0 = (h0 << 5) + h0 ^ h1;
- h1 = comparer.GetHashCode(item5);
- h1 = (h1 << 5) + h1 ^ comparer.GetHashCode(item6);
- h1 = (h1 << 5) + h1 ^ comparer.GetHashCode(item7);
- h0 = (h0 << 5) + h0 ^ h1;
- return h0;
- }
- string ITuple.ToString()
- {
- return String.Format("{0}, {1}, {2}, {3}, {4}, {5}, {6}", item1, item2, item3, item4, item5, item6, item7);
- }
- public override string ToString()
- {
- return "(" + ((ITuple)this).ToString() + ")";
- }
- public bool Equals(Tuple<T1, T2, T3, T4, T5, T6, T7> other)
- {
- var comparer1 = EqualityComparer<T1>.Default;
- var comparer2 = EqualityComparer<T2>.Default;
- var comparer3 = EqualityComparer<T3>.Default;
- var comparer4 = EqualityComparer<T4>.Default;
- var comparer5 = EqualityComparer<T5>.Default;
- var comparer6 = EqualityComparer<T6>.Default;
- var comparer7 = EqualityComparer<T7>.Default;
- return comparer1.Equals(item1, other.Item1) &&
- comparer2.Equals(item2, other.Item2) &&
- comparer3.Equals(item3, other.Item3) &&
- comparer4.Equals(item4, other.Item4) &&
- comparer5.Equals(item5, other.Item5) &&
- comparer6.Equals(item6, other.Item6) &&
- comparer7.Equals(item7, other.Item7);
- }
- }
- [Serializable]
- public partial class Tuple<T1, T2, T3, T4, T5, T6, T7, TRest> : IStructuralEquatable, IStructuralComparable, IComparable, ITuple, IEquatable<Tuple<T1, T2, T3, T4, T5, T6, T7, TRest>>
- {
- T1 item1;
- T2 item2;
- T3 item3;
- T4 item4;
- T5 item5;
- T6 item6;
- T7 item7;
- TRest rest;
- public T1 Item1
- {
- get { return item1; }
- }
- public T2 Item2
- {
- get { return item2; }
- }
- public T3 Item3
- {
- get { return item3; }
- }
- public T4 Item4
- {
- get { return item4; }
- }
- public T5 Item5
- {
- get { return item5; }
- }
- public T6 Item6
- {
- get { return item6; }
- }
- public T7 Item7
- {
- get { return item7; }
- }
- public TRest Rest
- {
- get { return rest; }
- }
- int IComparable.CompareTo(object obj)
- {
- return ((IStructuralComparable)this).CompareTo(obj, Comparer<object>.Default);
- }
- int IStructuralComparable.CompareTo(object other, IComparer comparer)
- {
- if (other == null) return 1;
- if (!(other is Tuple<T1, T2, T3, T4, T5, T6, T7, TRest>))
- {
- throw new ArgumentException("other");
- }
- var t = (Tuple<T1, T2, T3, T4, T5, T6, T7, TRest>)other;
- int res = comparer.Compare(item1, t.item1);
- if (res != 0) return res;
- res = comparer.Compare(item2, t.item2);
- if (res != 0) return res;
- res = comparer.Compare(item3, t.item3);
- if (res != 0) return res;
- res = comparer.Compare(item4, t.item4);
- if (res != 0) return res;
- res = comparer.Compare(item5, t.item5);
- if (res != 0) return res;
- res = comparer.Compare(item6, t.item6);
- if (res != 0) return res;
- res = comparer.Compare(item7, t.item7);
- if (res != 0) return res;
- return comparer.Compare(rest, t.rest);
- }
- public override bool Equals(object obj)
- {
- return ((IStructuralEquatable)this).Equals(obj, EqualityComparer<object>.Default);
- }
- bool IStructuralEquatable.Equals(object other, IEqualityComparer comparer)
- {
- if (!(other is Tuple<T1, T2, T3, T4, T5, T6, T7, TRest>))
- return false;
- var t = (Tuple<T1, T2, T3, T4, T5, T6, T7, TRest>)other;
- return comparer.Equals(item1, t.item1) &&
- comparer.Equals(item2, t.item2) &&
- comparer.Equals(item3, t.item3) &&
- comparer.Equals(item4, t.item4) &&
- comparer.Equals(item5, t.item5) &&
- comparer.Equals(item6, t.item6) &&
- comparer.Equals(item7, t.item7) &&
- comparer.Equals(rest, t.rest);
- }
- public override int GetHashCode()
- {
- var comparer1 = EqualityComparer<T1>.Default;
- var comparer2 = EqualityComparer<T2>.Default;
- var comparer3 = EqualityComparer<T3>.Default;
- var comparer4 = EqualityComparer<T4>.Default;
- var comparer5 = EqualityComparer<T5>.Default;
- var comparer6 = EqualityComparer<T6>.Default;
- var comparer7 = EqualityComparer<T7>.Default;
- var comparer8 = EqualityComparer<TRest>.Default;
- int h0, h1, h2;
- h0 = comparer1.GetHashCode(item1);
- h0 = (h0 << 5) + h0 ^ comparer2.GetHashCode(item2);
- h1 = comparer3.GetHashCode(item3);
- h1 = (h1 << 5) + h1 ^ comparer4.GetHashCode(item4);
- h0 = (h0 << 5) + h0 ^ h1;
- h1 = comparer5.GetHashCode(item5);
- h1 = (h1 << 5) + h1 ^ comparer6.GetHashCode(item6);
- h2 = comparer7.GetHashCode(item7);
- h2 = (h2 << 5) + h2 ^ comparer8.GetHashCode(rest);
- h1 = (h1 << 5) + h1 ^ h2;
- h0 = (h0 << 5) + h0 ^ h1;
- return h0;
- }
- int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
- {
- int h0, h1, h2;
- h0 = comparer.GetHashCode(item1);
- h0 = (h0 << 5) + h0 ^ comparer.GetHashCode(item2);
- h1 = comparer.GetHashCode(item3);
- h1 = (h1 << 5) + h1 ^ comparer.GetHashCode(item4);
- h0 = (h0 << 5) + h0 ^ h1;
- h1 = comparer.GetHashCode(item5);
- h1 = (h1 << 5) + h1 ^ comparer.GetHashCode(item6);
- h2 = comparer.GetHashCode(item7);
- h2 = (h2 << 5) + h2 ^ comparer.GetHashCode(rest);
- h1 = (h1 << 5) + h1 ^ h2;
- h0 = (h0 << 5) + h0 ^ h1;
- return h0;
- }
- string ITuple.ToString()
- {
- return String.Format("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}", item1, item2, item3, item4, item5, item6, item7, ((ITuple)rest).ToString());
- }
- public override string ToString()
- {
- return "(" + ((ITuple)this).ToString() + ")";
- }
- public bool Equals(Tuple<T1, T2, T3, T4, T5, T6, T7, TRest> other)
- {
- var comparer1 = EqualityComparer<T1>.Default;
- var comparer2 = EqualityComparer<T2>.Default;
- var comparer3 = EqualityComparer<T3>.Default;
- var comparer4 = EqualityComparer<T4>.Default;
- var comparer5 = EqualityComparer<T5>.Default;
- var comparer6 = EqualityComparer<T6>.Default;
- var comparer7 = EqualityComparer<T7>.Default;
- var comparer8 = EqualityComparer<TRest>.Default;
- return comparer1.Equals(item1, other.Item1) &&
- comparer2.Equals(item2, other.Item2) &&
- comparer3.Equals(item3, other.Item3) &&
- comparer4.Equals(item4, other.Item4) &&
- comparer5.Equals(item5, other.Item5) &&
- comparer6.Equals(item6, other.Item6) &&
- comparer7.Equals(item7, other.Item7) &&
- comparer8.Equals(rest, other.rest);
- }
- }
- }
- #endif
|