| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142 |
- // Licensed to the .NET Foundation under one or more agreements.
- // The .NET Foundation licenses this file to you under the MIT license.
- // See the LICENSE file in the project root for more information.
- using System.Collections;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Runtime.CompilerServices;
- using System.Text;
- namespace System
- {
- /// <summary>
- /// Helper so we can call some tuple methods recursively without knowing the underlying types.
- /// </summary>
- internal interface ITupleInternal : ITuple
- {
- string ToString(StringBuilder sb);
- int GetHashCode(IEqualityComparer comparer);
- }
- public static class Tuple
- {
- public static Tuple<T1> Create<T1>(T1 item1)
- {
- return new Tuple<T1>(item1);
- }
- public static Tuple<T1, T2> Create<T1, T2>(T1 item1, T2 item2)
- {
- return new Tuple<T1, T2>(item1, item2);
- }
- 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, 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, 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, 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, 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, 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));
- }
- // Note: F# compiler depends on the exact tuple hashing algorithm. Do not ever change it.
- // From System.Web.Util.HashCodeCombiner
- internal static int CombineHashCodes(int h1, int h2)
- {
- return ((h1 << 5) + h1) ^ h2;
- }
- internal static int CombineHashCodes(int h1, int h2, int h3)
- {
- return CombineHashCodes(CombineHashCodes(h1, h2), h3);
- }
- internal static int CombineHashCodes(int h1, int h2, int h3, int h4)
- {
- return CombineHashCodes(CombineHashCodes(h1, h2), CombineHashCodes(h3, h4));
- }
- internal static int CombineHashCodes(int h1, int h2, int h3, int h4, int h5)
- {
- return CombineHashCodes(CombineHashCodes(h1, h2, h3, h4), h5);
- }
- internal static int CombineHashCodes(int h1, int h2, int h3, int h4, int h5, int h6)
- {
- return CombineHashCodes(CombineHashCodes(h1, h2, h3, h4), CombineHashCodes(h5, h6));
- }
- internal static int CombineHashCodes(int h1, int h2, int h3, int h4, int h5, int h6, int h7)
- {
- return CombineHashCodes(CombineHashCodes(h1, h2, h3, h4), CombineHashCodes(h5, h6, h7));
- }
- internal static int CombineHashCodes(int h1, int h2, int h3, int h4, int h5, int h6, int h7, int h8)
- {
- return CombineHashCodes(CombineHashCodes(h1, h2, h3, h4), CombineHashCodes(h5, h6, h7, h8));
- }
- }
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class Tuple<T1> : IStructuralEquatable, IStructuralComparable, IComparable, ITupleInternal, ITuple
- {
- private readonly T1 m_Item1; // Do not rename (binary serialization)
- public T1 Item1 => m_Item1;
- public Tuple(T1 item1)
- {
- m_Item1 = item1;
- }
- public override bool Equals(object? obj)
- {
- return ((IStructuralEquatable)this).Equals(obj, EqualityComparer<object>.Default);
- }
- bool IStructuralEquatable.Equals(object? other, IEqualityComparer comparer)
- {
- if (other == null) return false;
- if (!(other is Tuple<T1> objTuple))
- {
- return false;
- }
- return comparer.Equals(m_Item1, objTuple.m_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> objTuple))
- {
- throw new ArgumentException(SR.Format(SR.ArgumentException_TupleIncorrectType, GetType()), nameof(other));
- }
- return comparer.Compare(m_Item1, objTuple.m_Item1);
- }
- public override int GetHashCode()
- {
- return ((IStructuralEquatable)this).GetHashCode(EqualityComparer<object>.Default);
- }
- int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
- {
- return comparer.GetHashCode(m_Item1!);
- }
- int ITupleInternal.GetHashCode(IEqualityComparer comparer)
- {
- return ((IStructuralEquatable)this).GetHashCode(comparer);
- }
- public override string ToString()
- {
- StringBuilder sb = new StringBuilder();
- sb.Append('(');
- return ((ITupleInternal)this).ToString(sb);
- }
- string ITupleInternal.ToString(StringBuilder sb)
- {
- sb.Append(m_Item1);
- sb.Append(')');
- return sb.ToString();
- }
- /// <summary>
- /// The number of positions in this data structure.
- /// </summary>
- int ITuple.Length => 1;
- /// <summary>
- /// Get the element at position <param name="index"/>.
- /// </summary>
- object? ITuple.this[int index]
- {
- get
- {
- if (index != 0)
- {
- throw new IndexOutOfRangeException();
- }
- return Item1;
- }
- }
- }
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class Tuple<T1, T2> : IStructuralEquatable, IStructuralComparable, IComparable, ITupleInternal, ITuple
- {
- private readonly T1 m_Item1; // Do not rename (binary serialization)
- private readonly T2 m_Item2; // Do not rename (binary serialization)
- public T1 Item1 => m_Item1;
- public T2 Item2 => m_Item2;
- public Tuple(T1 item1, T2 item2)
- {
- m_Item1 = item1;
- m_Item2 = item2;
- }
- public override bool Equals(object? obj)
- {
- return ((IStructuralEquatable)this).Equals(obj, EqualityComparer<object>.Default);
- }
- bool IStructuralEquatable.Equals(object? other, IEqualityComparer comparer)
- {
- if (other == null) return false;
- if (!(other is Tuple<T1, T2> objTuple))
- {
- return false;
- }
- return comparer.Equals(m_Item1, objTuple.m_Item1) && comparer.Equals(m_Item2, objTuple.m_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> objTuple))
- {
- throw new ArgumentException(SR.Format(SR.ArgumentException_TupleIncorrectType, GetType()), nameof(other));
- }
- int c = comparer.Compare(m_Item1, objTuple.m_Item1);
- if (c != 0) return c;
- return comparer.Compare(m_Item2, objTuple.m_Item2);
- }
- public override int GetHashCode()
- {
- return ((IStructuralEquatable)this).GetHashCode(EqualityComparer<object>.Default);
- }
- int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
- {
- return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item1!), comparer.GetHashCode(m_Item2!));
- }
- int ITupleInternal.GetHashCode(IEqualityComparer comparer)
- {
- return ((IStructuralEquatable)this).GetHashCode(comparer);
- }
- public override string ToString()
- {
- StringBuilder sb = new StringBuilder();
- sb.Append('(');
- return ((ITupleInternal)this).ToString(sb);
- }
- string ITupleInternal.ToString(StringBuilder sb)
- {
- sb.Append(m_Item1);
- sb.Append(", ");
- sb.Append(m_Item2);
- sb.Append(')');
- return sb.ToString();
- }
- /// <summary>
- /// The number of positions in this data structure.
- /// </summary>
- int ITuple.Length => 2;
- /// <summary>
- /// Get the element at position <param name="index"/>.
- /// </summary>
- object? ITuple.this[int index] =>
- index switch
- {
- 0 => Item1,
- 1 => Item2,
- _ => throw new IndexOutOfRangeException(),
- };
- }
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class Tuple<T1, T2, T3> : IStructuralEquatable, IStructuralComparable, IComparable, ITupleInternal, ITuple
- {
- private readonly T1 m_Item1; // Do not rename (binary serialization)
- private readonly T2 m_Item2; // Do not rename (binary serialization)
- private readonly T3 m_Item3; // Do not rename (binary serialization)
- public T1 Item1 => m_Item1;
- public T2 Item2 => m_Item2;
- public T3 Item3 => m_Item3;
- public Tuple(T1 item1, T2 item2, T3 item3)
- {
- m_Item1 = item1;
- m_Item2 = item2;
- m_Item3 = item3;
- }
- public override bool Equals(object? obj)
- {
- return ((IStructuralEquatable)this).Equals(obj, EqualityComparer<object>.Default);
- }
- bool IStructuralEquatable.Equals(object? other, IEqualityComparer comparer)
- {
- if (other == null) return false;
- if (!(other is Tuple<T1, T2, T3> objTuple))
- {
- return false;
- }
- return comparer.Equals(m_Item1, objTuple.m_Item1) && comparer.Equals(m_Item2, objTuple.m_Item2) && comparer.Equals(m_Item3, objTuple.m_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> objTuple))
- {
- throw new ArgumentException(SR.Format(SR.ArgumentException_TupleIncorrectType, GetType()), nameof(other));
- }
- int c = comparer.Compare(m_Item1, objTuple.m_Item1);
- if (c != 0) return c;
- c = comparer.Compare(m_Item2, objTuple.m_Item2);
- if (c != 0) return c;
- return comparer.Compare(m_Item3, objTuple.m_Item3);
- }
- public override int GetHashCode()
- {
- return ((IStructuralEquatable)this).GetHashCode(EqualityComparer<object>.Default);
- }
- int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
- {
- return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item1!), comparer.GetHashCode(m_Item2!), comparer.GetHashCode(m_Item3!));
- }
- int ITupleInternal.GetHashCode(IEqualityComparer comparer)
- {
- return ((IStructuralEquatable)this).GetHashCode(comparer);
- }
- public override string ToString()
- {
- StringBuilder sb = new StringBuilder();
- sb.Append('(');
- return ((ITupleInternal)this).ToString(sb);
- }
- string ITupleInternal.ToString(StringBuilder sb)
- {
- sb.Append(m_Item1);
- sb.Append(", ");
- sb.Append(m_Item2);
- sb.Append(", ");
- sb.Append(m_Item3);
- sb.Append(')');
- return sb.ToString();
- }
- /// <summary>
- /// The number of positions in this data structure.
- /// </summary>
- int ITuple.Length => 3;
- /// <summary>
- /// Get the element at position <param name="index"/>.
- /// </summary>
- object? ITuple.this[int index] =>
- index switch
- {
- 0 => Item1,
- 1 => Item2,
- 2 => Item3,
- _ => throw new IndexOutOfRangeException(),
- };
- }
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class Tuple<T1, T2, T3, T4> : IStructuralEquatable, IStructuralComparable, IComparable, ITupleInternal, ITuple
- {
- private readonly T1 m_Item1; // Do not rename (binary serialization)
- private readonly T2 m_Item2; // Do not rename (binary serialization)
- private readonly T3 m_Item3; // Do not rename (binary serialization)
- private readonly T4 m_Item4; // Do not rename (binary serialization)
- public T1 Item1 => m_Item1;
- public T2 Item2 => m_Item2;
- public T3 Item3 => m_Item3;
- public T4 Item4 => m_Item4;
- public Tuple(T1 item1, T2 item2, T3 item3, T4 item4)
- {
- m_Item1 = item1;
- m_Item2 = item2;
- m_Item3 = item3;
- m_Item4 = item4;
- }
- public override bool Equals(object? obj)
- {
- return ((IStructuralEquatable)this).Equals(obj, EqualityComparer<object>.Default);
- }
- bool IStructuralEquatable.Equals(object? other, IEqualityComparer comparer)
- {
- if (other == null) return false;
- if (!(other is Tuple<T1, T2, T3, T4> objTuple))
- {
- return false;
- }
- return comparer.Equals(m_Item1, objTuple.m_Item1) && comparer.Equals(m_Item2, objTuple.m_Item2) && comparer.Equals(m_Item3, objTuple.m_Item3) && comparer.Equals(m_Item4, objTuple.m_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> objTuple))
- {
- throw new ArgumentException(SR.Format(SR.ArgumentException_TupleIncorrectType, GetType()), nameof(other));
- }
- int c = comparer.Compare(m_Item1, objTuple.m_Item1);
- if (c != 0) return c;
- c = comparer.Compare(m_Item2, objTuple.m_Item2);
- if (c != 0) return c;
- c = comparer.Compare(m_Item3, objTuple.m_Item3);
- if (c != 0) return c;
- return comparer.Compare(m_Item4, objTuple.m_Item4);
- }
- public override int GetHashCode()
- {
- return ((IStructuralEquatable)this).GetHashCode(EqualityComparer<object>.Default);
- }
- int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
- {
- return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item1!), comparer.GetHashCode(m_Item2!), comparer.GetHashCode(m_Item3!), comparer.GetHashCode(m_Item4!));
- }
- int ITupleInternal.GetHashCode(IEqualityComparer comparer)
- {
- return ((IStructuralEquatable)this).GetHashCode(comparer);
- }
- public override string ToString()
- {
- StringBuilder sb = new StringBuilder();
- sb.Append('(');
- return ((ITupleInternal)this).ToString(sb);
- }
- string ITupleInternal.ToString(StringBuilder sb)
- {
- sb.Append(m_Item1);
- sb.Append(", ");
- sb.Append(m_Item2);
- sb.Append(", ");
- sb.Append(m_Item3);
- sb.Append(", ");
- sb.Append(m_Item4);
- sb.Append(')');
- return sb.ToString();
- }
- /// <summary>
- /// The number of positions in this data structure.
- /// </summary>
- int ITuple.Length => 4;
- /// <summary>
- /// Get the element at position <param name="index"/>.
- /// </summary>
- object? ITuple.this[int index] =>
- index switch
- {
- 0 => Item1,
- 1 => Item2,
- 2 => Item3,
- 3 => Item4,
- _ => throw new IndexOutOfRangeException(),
- };
- }
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class Tuple<T1, T2, T3, T4, T5> : IStructuralEquatable, IStructuralComparable, IComparable, ITupleInternal, ITuple
- {
- private readonly T1 m_Item1; // Do not rename (binary serialization)
- private readonly T2 m_Item2; // Do not rename (binary serialization)
- private readonly T3 m_Item3; // Do not rename (binary serialization)
- private readonly T4 m_Item4; // Do not rename (binary serialization)
- private readonly T5 m_Item5; // Do not rename (binary serialization)
- public T1 Item1 => m_Item1;
- public T2 Item2 => m_Item2;
- public T3 Item3 => m_Item3;
- public T4 Item4 => m_Item4;
- public T5 Item5 => m_Item5;
- public Tuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5)
- {
- m_Item1 = item1;
- m_Item2 = item2;
- m_Item3 = item3;
- m_Item4 = item4;
- m_Item5 = item5;
- }
- public override bool Equals(object? obj)
- {
- return ((IStructuralEquatable)this).Equals(obj, EqualityComparer<object>.Default);
- }
- bool IStructuralEquatable.Equals(object? other, IEqualityComparer comparer)
- {
- if (other == null) return false;
- if (!(other is Tuple<T1, T2, T3, T4, T5> objTuple))
- {
- return false;
- }
- return comparer.Equals(m_Item1, objTuple.m_Item1) && comparer.Equals(m_Item2, objTuple.m_Item2) && comparer.Equals(m_Item3, objTuple.m_Item3) && comparer.Equals(m_Item4, objTuple.m_Item4) && comparer.Equals(m_Item5, objTuple.m_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> objTuple))
- {
- throw new ArgumentException(SR.Format(SR.ArgumentException_TupleIncorrectType, GetType()), nameof(other));
- }
- int c = comparer.Compare(m_Item1, objTuple.m_Item1);
- if (c != 0) return c;
- c = comparer.Compare(m_Item2, objTuple.m_Item2);
- if (c != 0) return c;
- c = comparer.Compare(m_Item3, objTuple.m_Item3);
- if (c != 0) return c;
- c = comparer.Compare(m_Item4, objTuple.m_Item4);
- if (c != 0) return c;
- return comparer.Compare(m_Item5, objTuple.m_Item5);
- }
- public override int GetHashCode()
- {
- return ((IStructuralEquatable)this).GetHashCode(EqualityComparer<object>.Default);
- }
- int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
- {
- return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item1!), comparer.GetHashCode(m_Item2!), comparer.GetHashCode(m_Item3!), comparer.GetHashCode(m_Item4!), comparer.GetHashCode(m_Item5!));
- }
- int ITupleInternal.GetHashCode(IEqualityComparer comparer)
- {
- return ((IStructuralEquatable)this).GetHashCode(comparer);
- }
- public override string ToString()
- {
- StringBuilder sb = new StringBuilder();
- sb.Append('(');
- return ((ITupleInternal)this).ToString(sb);
- }
- string ITupleInternal.ToString(StringBuilder sb)
- {
- sb.Append(m_Item1);
- sb.Append(", ");
- sb.Append(m_Item2);
- sb.Append(", ");
- sb.Append(m_Item3);
- sb.Append(", ");
- sb.Append(m_Item4);
- sb.Append(", ");
- sb.Append(m_Item5);
- sb.Append(')');
- return sb.ToString();
- }
- /// <summary>
- /// The number of positions in this data structure.
- /// </summary>
- int ITuple.Length => 5;
- /// <summary>
- /// Get the element at position <param name="index"/>.
- /// </summary>
- object? ITuple.this[int index] =>
- index switch
- {
- 0 => Item1,
- 1 => Item2,
- 2 => Item3,
- 3 => Item4,
- 4 => Item5,
- _ => throw new IndexOutOfRangeException(),
- };
- }
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class Tuple<T1, T2, T3, T4, T5, T6> : IStructuralEquatable, IStructuralComparable, IComparable, ITupleInternal, ITuple
- {
- private readonly T1 m_Item1; // Do not rename (binary serialization)
- private readonly T2 m_Item2; // Do not rename (binary serialization)
- private readonly T3 m_Item3; // Do not rename (binary serialization)
- private readonly T4 m_Item4; // Do not rename (binary serialization)
- private readonly T5 m_Item5; // Do not rename (binary serialization)
- private readonly T6 m_Item6; // Do not rename (binary serialization)
- public T1 Item1 => m_Item1;
- public T2 Item2 => m_Item2;
- public T3 Item3 => m_Item3;
- public T4 Item4 => m_Item4;
- public T5 Item5 => m_Item5;
- public T6 Item6 => m_Item6;
- public Tuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6)
- {
- m_Item1 = item1;
- m_Item2 = item2;
- m_Item3 = item3;
- m_Item4 = item4;
- m_Item5 = item5;
- m_Item6 = item6;
- }
- public override bool Equals(object? obj)
- {
- return ((IStructuralEquatable)this).Equals(obj, EqualityComparer<object>.Default);
- }
- bool IStructuralEquatable.Equals(object? other, IEqualityComparer comparer)
- {
- if (other == null) return false;
- if (!(other is Tuple<T1, T2, T3, T4, T5, T6> objTuple))
- {
- return false;
- }
- return comparer.Equals(m_Item1, objTuple.m_Item1) && comparer.Equals(m_Item2, objTuple.m_Item2) && comparer.Equals(m_Item3, objTuple.m_Item3) && comparer.Equals(m_Item4, objTuple.m_Item4) && comparer.Equals(m_Item5, objTuple.m_Item5) && comparer.Equals(m_Item6, objTuple.m_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> objTuple))
- {
- throw new ArgumentException(SR.Format(SR.ArgumentException_TupleIncorrectType, GetType()), nameof(other));
- }
- int c = comparer.Compare(m_Item1, objTuple.m_Item1);
- if (c != 0) return c;
- c = comparer.Compare(m_Item2, objTuple.m_Item2);
- if (c != 0) return c;
- c = comparer.Compare(m_Item3, objTuple.m_Item3);
- if (c != 0) return c;
- c = comparer.Compare(m_Item4, objTuple.m_Item4);
- if (c != 0) return c;
- c = comparer.Compare(m_Item5, objTuple.m_Item5);
- if (c != 0) return c;
- return comparer.Compare(m_Item6, objTuple.m_Item6);
- }
- public override int GetHashCode()
- {
- return ((IStructuralEquatable)this).GetHashCode(EqualityComparer<object>.Default);
- }
- int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
- {
- return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item1!), comparer.GetHashCode(m_Item2!), comparer.GetHashCode(m_Item3!), comparer.GetHashCode(m_Item4!), comparer.GetHashCode(m_Item5!), comparer.GetHashCode(m_Item6!));
- }
- int ITupleInternal.GetHashCode(IEqualityComparer comparer)
- {
- return ((IStructuralEquatable)this).GetHashCode(comparer);
- }
- public override string ToString()
- {
- StringBuilder sb = new StringBuilder();
- sb.Append('(');
- return ((ITupleInternal)this).ToString(sb);
- }
- string ITupleInternal.ToString(StringBuilder sb)
- {
- sb.Append(m_Item1);
- sb.Append(", ");
- sb.Append(m_Item2);
- sb.Append(", ");
- sb.Append(m_Item3);
- sb.Append(", ");
- sb.Append(m_Item4);
- sb.Append(", ");
- sb.Append(m_Item5);
- sb.Append(", ");
- sb.Append(m_Item6);
- sb.Append(')');
- return sb.ToString();
- }
- /// <summary>
- /// The number of positions in this data structure.
- /// </summary>
- int ITuple.Length => 6;
- /// <summary>
- /// Get the element at position <param name="index"/>.
- /// </summary>
- object? ITuple.this[int index] =>
- index switch
- {
- 0 => Item1,
- 1 => Item2,
- 2 => Item3,
- 3 => Item4,
- 4 => Item5,
- 5 => Item6,
- _ => throw new IndexOutOfRangeException(),
- };
- }
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class Tuple<T1, T2, T3, T4, T5, T6, T7> : IStructuralEquatable, IStructuralComparable, IComparable, ITupleInternal, ITuple
- {
- private readonly T1 m_Item1; // Do not rename (binary serialization)
- private readonly T2 m_Item2; // Do not rename (binary serialization)
- private readonly T3 m_Item3; // Do not rename (binary serialization)
- private readonly T4 m_Item4; // Do not rename (binary serialization)
- private readonly T5 m_Item5; // Do not rename (binary serialization)
- private readonly T6 m_Item6; // Do not rename (binary serialization)
- private readonly T7 m_Item7; // Do not rename (binary serialization)
- public T1 Item1 => m_Item1;
- public T2 Item2 => m_Item2;
- public T3 Item3 => m_Item3;
- public T4 Item4 => m_Item4;
- public T5 Item5 => m_Item5;
- public T6 Item6 => m_Item6;
- public T7 Item7 => m_Item7;
- public Tuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7)
- {
- m_Item1 = item1;
- m_Item2 = item2;
- m_Item3 = item3;
- m_Item4 = item4;
- m_Item5 = item5;
- m_Item6 = item6;
- m_Item7 = item7;
- }
- public override bool Equals(object? obj)
- {
- return ((IStructuralEquatable)this).Equals(obj, EqualityComparer<object>.Default);
- }
- bool IStructuralEquatable.Equals(object? other, IEqualityComparer comparer)
- {
- if (other == null) return false;
- if (!(other is Tuple<T1, T2, T3, T4, T5, T6, T7> objTuple))
- {
- return false;
- }
- return comparer.Equals(m_Item1, objTuple.m_Item1) && comparer.Equals(m_Item2, objTuple.m_Item2) && comparer.Equals(m_Item3, objTuple.m_Item3) && comparer.Equals(m_Item4, objTuple.m_Item4) && comparer.Equals(m_Item5, objTuple.m_Item5) && comparer.Equals(m_Item6, objTuple.m_Item6) && comparer.Equals(m_Item7, objTuple.m_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> objTuple))
- {
- throw new ArgumentException(SR.Format(SR.ArgumentException_TupleIncorrectType, GetType()), nameof(other));
- }
- int c = comparer.Compare(m_Item1, objTuple.m_Item1);
- if (c != 0) return c;
- c = comparer.Compare(m_Item2, objTuple.m_Item2);
- if (c != 0) return c;
- c = comparer.Compare(m_Item3, objTuple.m_Item3);
- if (c != 0) return c;
- c = comparer.Compare(m_Item4, objTuple.m_Item4);
- if (c != 0) return c;
- c = comparer.Compare(m_Item5, objTuple.m_Item5);
- if (c != 0) return c;
- c = comparer.Compare(m_Item6, objTuple.m_Item6);
- if (c != 0) return c;
- return comparer.Compare(m_Item7, objTuple.m_Item7);
- }
- public override int GetHashCode()
- {
- return ((IStructuralEquatable)this).GetHashCode(EqualityComparer<object>.Default);
- }
- int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
- {
- return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item1!), comparer.GetHashCode(m_Item2!), comparer.GetHashCode(m_Item3!), comparer.GetHashCode(m_Item4!), comparer.GetHashCode(m_Item5!), comparer.GetHashCode(m_Item6!), comparer.GetHashCode(m_Item7!));
- }
- int ITupleInternal.GetHashCode(IEqualityComparer comparer)
- {
- return ((IStructuralEquatable)this).GetHashCode(comparer);
- }
- public override string ToString()
- {
- StringBuilder sb = new StringBuilder();
- sb.Append('(');
- return ((ITupleInternal)this).ToString(sb);
- }
- string ITupleInternal.ToString(StringBuilder sb)
- {
- sb.Append(m_Item1);
- sb.Append(", ");
- sb.Append(m_Item2);
- sb.Append(", ");
- sb.Append(m_Item3);
- sb.Append(", ");
- sb.Append(m_Item4);
- sb.Append(", ");
- sb.Append(m_Item5);
- sb.Append(", ");
- sb.Append(m_Item6);
- sb.Append(", ");
- sb.Append(m_Item7);
- sb.Append(')');
- return sb.ToString();
- }
- /// <summary>
- /// The number of positions in this data structure.
- /// </summary>
- int ITuple.Length => 7;
- /// <summary>
- /// Get the element at position <param name="index"/>.
- /// </summary>
- object? ITuple.this[int index] =>
- index switch
- {
- 0 => Item1,
- 1 => Item2,
- 2 => Item3,
- 3 => Item4,
- 4 => Item5,
- 5 => Item6,
- 6 => Item7,
- _ => throw new IndexOutOfRangeException(),
- };
- }
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class Tuple<T1, T2, T3, T4, T5, T6, T7, TRest> : IStructuralEquatable, IStructuralComparable, IComparable, ITupleInternal, ITuple where TRest : notnull
- {
- private readonly T1 m_Item1; // Do not rename (binary serialization)
- private readonly T2 m_Item2; // Do not rename (binary serialization)
- private readonly T3 m_Item3; // Do not rename (binary serialization)
- private readonly T4 m_Item4; // Do not rename (binary serialization)
- private readonly T5 m_Item5; // Do not rename (binary serialization)
- private readonly T6 m_Item6; // Do not rename (binary serialization)
- private readonly T7 m_Item7; // Do not rename (binary serialization)
- private readonly TRest m_Rest; // Do not rename (binary serialization)
- public T1 Item1 => m_Item1;
- public T2 Item2 => m_Item2;
- public T3 Item3 => m_Item3;
- public T4 Item4 => m_Item4;
- public T5 Item5 => m_Item5;
- public T6 Item6 => m_Item6;
- public T7 Item7 => m_Item7;
- public TRest Rest => m_Rest;
- public Tuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7, TRest rest)
- {
- if (!(rest is ITupleInternal))
- {
- throw new ArgumentException(SR.ArgumentException_TupleLastArgumentNotATuple);
- }
- m_Item1 = item1;
- m_Item2 = item2;
- m_Item3 = item3;
- m_Item4 = item4;
- m_Item5 = item5;
- m_Item6 = item6;
- m_Item7 = item7;
- m_Rest = rest;
- }
- public override bool Equals(object? obj)
- {
- return ((IStructuralEquatable)this).Equals(obj, EqualityComparer<object>.Default);
- }
- bool IStructuralEquatable.Equals(object? other, IEqualityComparer comparer)
- {
- if (other == null) return false;
- if (!(other is Tuple<T1, T2, T3, T4, T5, T6, T7, TRest> objTuple))
- {
- return false;
- }
- return comparer.Equals(m_Item1, objTuple.m_Item1) && comparer.Equals(m_Item2, objTuple.m_Item2) && comparer.Equals(m_Item3, objTuple.m_Item3) && comparer.Equals(m_Item4, objTuple.m_Item4) && comparer.Equals(m_Item5, objTuple.m_Item5) && comparer.Equals(m_Item6, objTuple.m_Item6) && comparer.Equals(m_Item7, objTuple.m_Item7) && comparer.Equals(m_Rest, objTuple.m_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> objTuple))
- {
- throw new ArgumentException(SR.Format(SR.ArgumentException_TupleIncorrectType, GetType()), nameof(other));
- }
- int c = comparer.Compare(m_Item1, objTuple.m_Item1);
- if (c != 0) return c;
- c = comparer.Compare(m_Item2, objTuple.m_Item2);
- if (c != 0) return c;
- c = comparer.Compare(m_Item3, objTuple.m_Item3);
- if (c != 0) return c;
- c = comparer.Compare(m_Item4, objTuple.m_Item4);
- if (c != 0) return c;
- c = comparer.Compare(m_Item5, objTuple.m_Item5);
- if (c != 0) return c;
- c = comparer.Compare(m_Item6, objTuple.m_Item6);
- if (c != 0) return c;
- c = comparer.Compare(m_Item7, objTuple.m_Item7);
- if (c != 0) return c;
- return comparer.Compare(m_Rest, objTuple.m_Rest);
- }
- public override int GetHashCode()
- {
- return ((IStructuralEquatable)this).GetHashCode(EqualityComparer<object>.Default);
- }
- int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
- {
- // We want to have a limited hash in this case. We'll use the last 8 elements of the tuple
- ITupleInternal t = (ITupleInternal)m_Rest;
- if (t.Length >= 8) { return t.GetHashCode(comparer); }
- // In this case, the m_Rest member has fewer than 8 elements so we need to combine our elements with the elements in m_Rest.
- int k = 8 - t.Length;
- switch (k)
- {
- case 1:
- return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item7!), t.GetHashCode(comparer));
- case 2:
- return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item6!), comparer.GetHashCode(m_Item7!), t.GetHashCode(comparer));
- case 3:
- return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item5!), comparer.GetHashCode(m_Item6!), comparer.GetHashCode(m_Item7!), t.GetHashCode(comparer));
- case 4:
- return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item4!), comparer.GetHashCode(m_Item5!), comparer.GetHashCode(m_Item6!), comparer.GetHashCode(m_Item7!), t.GetHashCode(comparer));
- case 5:
- return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item3!), comparer.GetHashCode(m_Item4!), comparer.GetHashCode(m_Item5!), comparer.GetHashCode(m_Item6!), comparer.GetHashCode(m_Item7!), t.GetHashCode(comparer));
- case 6:
- return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item2!), comparer.GetHashCode(m_Item3!), comparer.GetHashCode(m_Item4!), comparer.GetHashCode(m_Item5!), comparer.GetHashCode(m_Item6!), comparer.GetHashCode(m_Item7!), t.GetHashCode(comparer));
- case 7:
- return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item1!), comparer.GetHashCode(m_Item2!), comparer.GetHashCode(m_Item3!), comparer.GetHashCode(m_Item4!), comparer.GetHashCode(m_Item5!), comparer.GetHashCode(m_Item6!), comparer.GetHashCode(m_Item7!), t.GetHashCode(comparer));
- }
- Debug.Fail("Missed all cases for computing Tuple hash code");
- return -1;
- }
- int ITupleInternal.GetHashCode(IEqualityComparer comparer)
- {
- return ((IStructuralEquatable)this).GetHashCode(comparer);
- }
- public override string ToString()
- {
- StringBuilder sb = new StringBuilder();
- sb.Append('(');
- return ((ITupleInternal)this).ToString(sb);
- }
- string ITupleInternal.ToString(StringBuilder sb)
- {
- sb.Append(m_Item1);
- sb.Append(", ");
- sb.Append(m_Item2);
- sb.Append(", ");
- sb.Append(m_Item3);
- sb.Append(", ");
- sb.Append(m_Item4);
- sb.Append(", ");
- sb.Append(m_Item5);
- sb.Append(", ");
- sb.Append(m_Item6);
- sb.Append(", ");
- sb.Append(m_Item7);
- sb.Append(", ");
- return ((ITupleInternal)m_Rest).ToString(sb);
- }
- /// <summary>
- /// The number of positions in this data structure.
- /// </summary>
- int ITuple.Length => 7 + ((ITupleInternal)Rest).Length;
- /// <summary>
- /// Get the element at position <param name="index"/>.
- /// </summary>
- object? ITuple.this[int index] =>
- index switch
- {
- 0 => Item1,
- 1 => Item2,
- 2 => Item3,
- 3 => Item4,
- 4 => Item5,
- 5 => Item6,
- 6 => Item7,
- _ => ((ITupleInternal)Rest)[index - 7],
- };
- }
- }
|