| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333 |
- // 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.InteropServices;
- using System.Runtime.CompilerServices;
- using HashHelpers = System.Numerics.Hashing.HashHelpers;
- namespace System
- {
- /// <summary>
- /// Helper so we can call some tuple methods recursively without knowing the underlying types.
- /// </summary>
- internal interface IValueTupleInternal : ITuple
- {
- int GetHashCode(IEqualityComparer comparer);
- string ToStringEnd();
- }
- /// <summary>
- /// The ValueTuple types (from arity 0 to 8) comprise the runtime implementation that underlies tuples in C# and struct tuples in F#.
- /// Aside from created via language syntax, they are most easily created via the ValueTuple.Create factory methods.
- /// The System.ValueTuple types differ from the System.Tuple types in that:
- /// - they are structs rather than classes,
- /// - they are mutable rather than readonly, and
- /// - their members (such as Item1, Item2, etc) are fields rather than properties.
- /// </summary>
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public struct ValueTuple
- : IEquatable<ValueTuple>, IStructuralEquatable, IStructuralComparable, IComparable, IComparable<ValueTuple>, IValueTupleInternal, ITuple
- {
- /// <summary>
- /// Returns a value that indicates whether the current <see cref="ValueTuple"/> instance is equal to a specified object.
- /// </summary>
- /// <param name="obj">The object to compare with this instance.</param>
- /// <returns><see langword="true"/> if <paramref name="obj"/> is a <see cref="ValueTuple"/>.</returns>
- public override bool Equals(object obj)
- {
- return obj is ValueTuple;
- }
- /// <summary>Returns a value indicating whether this instance is equal to a specified value.</summary>
- /// <param name="other">An instance to compare to this instance.</param>
- /// <returns>true if <paramref name="other"/> has the same value as this instance; otherwise, false.</returns>
- public bool Equals(ValueTuple other)
- {
- return true;
- }
- bool IStructuralEquatable.Equals(object other, IEqualityComparer comparer)
- {
- return other is ValueTuple;
- }
- int IComparable.CompareTo(object other)
- {
- if (other == null) return 1;
- if (!(other is ValueTuple))
- {
- throw new ArgumentException(SR.Format(SR.ArgumentException_ValueTupleIncorrectType, this.GetType().ToString()), nameof(other));
- }
- return 0;
- }
- /// <summary>Compares this instance to a specified instance and returns an indication of their relative values.</summary>
- /// <param name="other">An instance to compare.</param>
- /// <returns>
- /// A signed number indicating the relative values of this instance and <paramref name="other"/>.
- /// Returns less than zero if this instance is less than <paramref name="other"/>, zero if this
- /// instance is equal to <paramref name="other"/>, and greater than zero if this instance is greater
- /// than <paramref name="other"/>.
- /// </returns>
- public int CompareTo(ValueTuple other)
- {
- return 0;
- }
- int IStructuralComparable.CompareTo(object other, IComparer comparer)
- {
- if (other == null) return 1;
- if (!(other is ValueTuple))
- {
- throw new ArgumentException(SR.Format(SR.ArgumentException_ValueTupleIncorrectType, this.GetType().ToString()), nameof(other));
- }
- return 0;
- }
- /// <summary>Returns the hash code for this instance.</summary>
- /// <returns>A 32-bit signed integer hash code.</returns>
- public override int GetHashCode()
- {
- return 0;
- }
- int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
- {
- return 0;
- }
- int IValueTupleInternal.GetHashCode(IEqualityComparer comparer)
- {
- return 0;
- }
- /// <summary>
- /// Returns a string that represents the value of this <see cref="ValueTuple"/> instance.
- /// </summary>
- /// <returns>The string representation of this <see cref="ValueTuple"/> instance.</returns>
- /// <remarks>
- /// The string returned by this method takes the form <c>()</c>.
- /// </remarks>
- public override string ToString()
- {
- return "()";
- }
- string IValueTupleInternal.ToStringEnd()
- {
- return ")";
- }
- /// <summary>
- /// The number of positions in this data structure.
- /// </summary>
- int ITuple.Length => 0;
- /// <summary>
- /// Get the element at position <param name="index"/>.
- /// </summary>
- object ITuple.this[int index]
- {
- get
- {
- throw new IndexOutOfRangeException();
- }
- }
- /// <summary>Creates a new struct 0-tuple.</summary>
- /// <returns>A 0-tuple.</returns>
- public static ValueTuple Create() =>
- new ValueTuple();
- /// <summary>Creates a new struct 1-tuple, or singleton.</summary>
- /// <typeparam name="T1">The type of the first component of the tuple.</typeparam>
- /// <param name="item1">The value of the first component of the tuple.</param>
- /// <returns>A 1-tuple (singleton) whose value is (item1).</returns>
- public static ValueTuple<T1> Create<T1>(T1 item1) =>
- new ValueTuple<T1>(item1);
- /// <summary>Creates a new struct 2-tuple, or pair.</summary>
- /// <typeparam name="T1">The type of the first component of the tuple.</typeparam>
- /// <typeparam name="T2">The type of the second component of the tuple.</typeparam>
- /// <param name="item1">The value of the first component of the tuple.</param>
- /// <param name="item2">The value of the second component of the tuple.</param>
- /// <returns>A 2-tuple (pair) whose value is (item1, item2).</returns>
- public static ValueTuple<T1, T2> Create<T1, T2>(T1 item1, T2 item2) =>
- new ValueTuple<T1, T2>(item1, item2);
- /// <summary>Creates a new struct 3-tuple, or triple.</summary>
- /// <typeparam name="T1">The type of the first component of the tuple.</typeparam>
- /// <typeparam name="T2">The type of the second component of the tuple.</typeparam>
- /// <typeparam name="T3">The type of the third component of the tuple.</typeparam>
- /// <param name="item1">The value of the first component of the tuple.</param>
- /// <param name="item2">The value of the second component of the tuple.</param>
- /// <param name="item3">The value of the third component of the tuple.</param>
- /// <returns>A 3-tuple (triple) whose value is (item1, item2, item3).</returns>
- public static ValueTuple<T1, T2, T3> Create<T1, T2, T3>(T1 item1, T2 item2, T3 item3) =>
- new ValueTuple<T1, T2, T3>(item1, item2, item3);
- /// <summary>Creates a new struct 4-tuple, or quadruple.</summary>
- /// <typeparam name="T1">The type of the first component of the tuple.</typeparam>
- /// <typeparam name="T2">The type of the second component of the tuple.</typeparam>
- /// <typeparam name="T3">The type of the third component of the tuple.</typeparam>
- /// <typeparam name="T4">The type of the fourth component of the tuple.</typeparam>
- /// <param name="item1">The value of the first component of the tuple.</param>
- /// <param name="item2">The value of the second component of the tuple.</param>
- /// <param name="item3">The value of the third component of the tuple.</param>
- /// <param name="item4">The value of the fourth component of the tuple.</param>
- /// <returns>A 4-tuple (quadruple) whose value is (item1, item2, item3, item4).</returns>
- public static ValueTuple<T1, T2, T3, T4> Create<T1, T2, T3, T4>(T1 item1, T2 item2, T3 item3, T4 item4) =>
- new ValueTuple<T1, T2, T3, T4>(item1, item2, item3, item4);
- /// <summary>Creates a new struct 5-tuple, or quintuple.</summary>
- /// <typeparam name="T1">The type of the first component of the tuple.</typeparam>
- /// <typeparam name="T2">The type of the second component of the tuple.</typeparam>
- /// <typeparam name="T3">The type of the third component of the tuple.</typeparam>
- /// <typeparam name="T4">The type of the fourth component of the tuple.</typeparam>
- /// <typeparam name="T5">The type of the fifth component of the tuple.</typeparam>
- /// <param name="item1">The value of the first component of the tuple.</param>
- /// <param name="item2">The value of the second component of the tuple.</param>
- /// <param name="item3">The value of the third component of the tuple.</param>
- /// <param name="item4">The value of the fourth component of the tuple.</param>
- /// <param name="item5">The value of the fifth component of the tuple.</param>
- /// <returns>A 5-tuple (quintuple) whose value is (item1, item2, item3, item4, item5).</returns>
- public static ValueTuple<T1, T2, T3, T4, T5> Create<T1, T2, T3, T4, T5>(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5) =>
- new ValueTuple<T1, T2, T3, T4, T5>(item1, item2, item3, item4, item5);
- /// <summary>Creates a new struct 6-tuple, or sextuple.</summary>
- /// <typeparam name="T1">The type of the first component of the tuple.</typeparam>
- /// <typeparam name="T2">The type of the second component of the tuple.</typeparam>
- /// <typeparam name="T3">The type of the third component of the tuple.</typeparam>
- /// <typeparam name="T4">The type of the fourth component of the tuple.</typeparam>
- /// <typeparam name="T5">The type of the fifth component of the tuple.</typeparam>
- /// <typeparam name="T6">The type of the sixth component of the tuple.</typeparam>
- /// <param name="item1">The value of the first component of the tuple.</param>
- /// <param name="item2">The value of the second component of the tuple.</param>
- /// <param name="item3">The value of the third component of the tuple.</param>
- /// <param name="item4">The value of the fourth component of the tuple.</param>
- /// <param name="item5">The value of the fifth component of the tuple.</param>
- /// <param name="item6">The value of the sixth component of the tuple.</param>
- /// <returns>A 6-tuple (sextuple) whose value is (item1, item2, item3, item4, item5, item6).</returns>
- public static ValueTuple<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) =>
- new ValueTuple<T1, T2, T3, T4, T5, T6>(item1, item2, item3, item4, item5, item6);
- /// <summary>Creates a new struct 7-tuple, or septuple.</summary>
- /// <typeparam name="T1">The type of the first component of the tuple.</typeparam>
- /// <typeparam name="T2">The type of the second component of the tuple.</typeparam>
- /// <typeparam name="T3">The type of the third component of the tuple.</typeparam>
- /// <typeparam name="T4">The type of the fourth component of the tuple.</typeparam>
- /// <typeparam name="T5">The type of the fifth component of the tuple.</typeparam>
- /// <typeparam name="T6">The type of the sixth component of the tuple.</typeparam>
- /// <typeparam name="T7">The type of the seventh component of the tuple.</typeparam>
- /// <param name="item1">The value of the first component of the tuple.</param>
- /// <param name="item2">The value of the second component of the tuple.</param>
- /// <param name="item3">The value of the third component of the tuple.</param>
- /// <param name="item4">The value of the fourth component of the tuple.</param>
- /// <param name="item5">The value of the fifth component of the tuple.</param>
- /// <param name="item6">The value of the sixth component of the tuple.</param>
- /// <param name="item7">The value of the seventh component of the tuple.</param>
- /// <returns>A 7-tuple (septuple) whose value is (item1, item2, item3, item4, item5, item6, item7).</returns>
- public static ValueTuple<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) =>
- new ValueTuple<T1, T2, T3, T4, T5, T6, T7>(item1, item2, item3, item4, item5, item6, item7);
- /// <summary>Creates a new struct 8-tuple, or octuple.</summary>
- /// <typeparam name="T1">The type of the first component of the tuple.</typeparam>
- /// <typeparam name="T2">The type of the second component of the tuple.</typeparam>
- /// <typeparam name="T3">The type of the third component of the tuple.</typeparam>
- /// <typeparam name="T4">The type of the fourth component of the tuple.</typeparam>
- /// <typeparam name="T5">The type of the fifth component of the tuple.</typeparam>
- /// <typeparam name="T6">The type of the sixth component of the tuple.</typeparam>
- /// <typeparam name="T7">The type of the seventh component of the tuple.</typeparam>
- /// <typeparam name="T8">The type of the eighth component of the tuple.</typeparam>
- /// <param name="item1">The value of the first component of the tuple.</param>
- /// <param name="item2">The value of the second component of the tuple.</param>
- /// <param name="item3">The value of the third component of the tuple.</param>
- /// <param name="item4">The value of the fourth component of the tuple.</param>
- /// <param name="item5">The value of the fifth component of the tuple.</param>
- /// <param name="item6">The value of the sixth component of the tuple.</param>
- /// <param name="item7">The value of the seventh component of the tuple.</param>
- /// <param name="item8">The value of the eighth component of the tuple.</param>
- /// <returns>An 8-tuple (octuple) whose value is (item1, item2, item3, item4, item5, item6, item7, item8).</returns>
- public static ValueTuple<T1, T2, T3, T4, T5, T6, T7, ValueTuple<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) =>
- new ValueTuple<T1, T2, T3, T4, T5, T6, T7, ValueTuple<T8>>(item1, item2, item3, item4, item5, item6, item7, ValueTuple.Create(item8));
- internal static int CombineHashCodes(int h1, int h2)
- {
- return HashHelpers.Combine(HashHelpers.Combine(HashHelpers.RandomSeed, h1), h2);
- }
- internal static int CombineHashCodes(int h1, int h2, int h3)
- {
- return HashHelpers.Combine(CombineHashCodes(h1, h2), h3);
- }
- internal static int CombineHashCodes(int h1, int h2, int h3, int h4)
- {
- return HashHelpers.Combine(CombineHashCodes(h1, h2, h3), h4);
- }
- internal static int CombineHashCodes(int h1, int h2, int h3, int h4, int h5)
- {
- return HashHelpers.Combine(CombineHashCodes(h1, h2, h3, h4), h5);
- }
- internal static int CombineHashCodes(int h1, int h2, int h3, int h4, int h5, int h6)
- {
- return HashHelpers.Combine(CombineHashCodes(h1, h2, h3, h4, h5), h6);
- }
- internal static int CombineHashCodes(int h1, int h2, int h3, int h4, int h5, int h6, int h7)
- {
- return HashHelpers.Combine(CombineHashCodes(h1, h2, h3, h4, h5, h6), h7);
- }
- internal static int CombineHashCodes(int h1, int h2, int h3, int h4, int h5, int h6, int h7, int h8)
- {
- return HashHelpers.Combine(CombineHashCodes(h1, h2, h3, h4, h5, h6, h7), h8);
- }
- }
- /// <summary>Represents a 1-tuple, or singleton, as a value type.</summary>
- /// <typeparam name="T1">The type of the tuple's only component.</typeparam>
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public struct ValueTuple<T1>
- : IEquatable<ValueTuple<T1>>, IStructuralEquatable, IStructuralComparable, IComparable, IComparable<ValueTuple<T1>>, IValueTupleInternal, ITuple
- {
- /// <summary>
- /// The current <see cref="ValueTuple{T1}"/> instance's first component.
- /// </summary>
- public T1 Item1;
- /// <summary>
- /// Initializes a new instance of the <see cref="ValueTuple{T1}"/> value type.
- /// </summary>
- /// <param name="item1">The value of the tuple's first component.</param>
- public ValueTuple(T1 item1)
- {
- Item1 = item1;
- }
- /// <summary>
- /// Returns a value that indicates whether the current <see cref="ValueTuple{T1}"/> instance is equal to a specified object.
- /// </summary>
- /// <param name="obj">The object to compare with this instance.</param>
- /// <returns><see langword="true"/> if the current instance is equal to the specified object; otherwise, <see langword="false"/>.</returns>
- /// <remarks>
- /// The <paramref name="obj"/> parameter is considered to be equal to the current instance under the following conditions:
- /// <list type="bullet">
- /// <item><description>It is a <see cref="ValueTuple{T1}"/> value type.</description></item>
- /// <item><description>Its components are of the same types as those of the current instance.</description></item>
- /// <item><description>Its components are equal to those of the current instance. Equality is determined by the default object equality comparer for each component.</description></item>
- /// </list>
- /// </remarks>
- public override bool Equals(object obj)
- {
- return obj is ValueTuple<T1> && Equals((ValueTuple<T1>)obj);
- }
- /// <summary>
- /// Returns a value that indicates whether the current <see cref="ValueTuple{T1}"/>
- /// instance is equal to a specified <see cref="ValueTuple{T1}"/>.
- /// </summary>
- /// <param name="other">The tuple to compare with this instance.</param>
- /// <returns><see langword="true"/> if the current instance is equal to the specified tuple; otherwise, <see langword="false"/>.</returns>
- /// <remarks>
- /// The <paramref name="other"/> parameter is considered to be equal to the current instance if each of its field
- /// is equal to that of the current instance, using the default comparer for that field's type.
- /// </remarks>
- public bool Equals(ValueTuple<T1> other)
- {
- return EqualityComparer<T1>.Default.Equals(Item1, other.Item1);
- }
- bool IStructuralEquatable.Equals(object other, IEqualityComparer comparer)
- {
- if (other == null || !(other is ValueTuple<T1>)) return false;
- var objTuple = (ValueTuple<T1>)other;
- return comparer.Equals(Item1, objTuple.Item1);
- }
- int IComparable.CompareTo(object other)
- {
- if (other == null) return 1;
- if (!(other is ValueTuple<T1>))
- {
- throw new ArgumentException(SR.Format(SR.ArgumentException_ValueTupleIncorrectType, this.GetType().ToString()), nameof(other));
- }
- var objTuple = (ValueTuple<T1>)other;
- return Comparer<T1>.Default.Compare(Item1, objTuple.Item1);
- }
- /// <summary>Compares this instance to a specified instance and returns an indication of their relative values.</summary>
- /// <param name="other">An instance to compare.</param>
- /// <returns>
- /// A signed number indicating the relative values of this instance and <paramref name="other"/>.
- /// Returns less than zero if this instance is less than <paramref name="other"/>, zero if this
- /// instance is equal to <paramref name="other"/>, and greater than zero if this instance is greater
- /// than <paramref name="other"/>.
- /// </returns>
- public int CompareTo(ValueTuple<T1> other)
- {
- return Comparer<T1>.Default.Compare(Item1, other.Item1);
- }
- int IStructuralComparable.CompareTo(object other, IComparer comparer)
- {
- if (other == null) return 1;
- if (!(other is ValueTuple<T1>))
- {
- throw new ArgumentException(SR.Format(SR.ArgumentException_ValueTupleIncorrectType, this.GetType().ToString()), nameof(other));
- }
- var objTuple = (ValueTuple<T1>)other;
- return comparer.Compare(Item1, objTuple.Item1);
- }
- /// <summary>
- /// Returns the hash code for the current <see cref="ValueTuple{T1}"/> instance.
- /// </summary>
- /// <returns>A 32-bit signed integer hash code.</returns>
- public override int GetHashCode()
- {
- return Item1?.GetHashCode() ?? 0;
- }
- int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
- {
- return comparer.GetHashCode(Item1);
- }
- int IValueTupleInternal.GetHashCode(IEqualityComparer comparer)
- {
- return comparer.GetHashCode(Item1);
- }
- /// <summary>
- /// Returns a string that represents the value of this <see cref="ValueTuple{T1}"/> instance.
- /// </summary>
- /// <returns>The string representation of this <see cref="ValueTuple{T1}"/> instance.</returns>
- /// <remarks>
- /// The string returned by this method takes the form <c>(Item1)</c>,
- /// where <c>Item1</c> represents the value of <see cref="Item1"/>. If the field is <see langword="null"/>,
- /// it is represented as <see cref="string.Empty"/>.
- /// </remarks>
- public override string ToString()
- {
- return "(" + Item1?.ToString() + ")";
- }
- string IValueTupleInternal.ToStringEnd()
- {
- return Item1?.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;
- }
- }
- }
- /// <summary>
- /// Represents a 2-tuple, or pair, as a value type.
- /// </summary>
- /// <typeparam name="T1">The type of the tuple's first component.</typeparam>
- /// <typeparam name="T2">The type of the tuple's second component.</typeparam>
- [Serializable]
- [StructLayout(LayoutKind.Auto)]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public struct ValueTuple<T1, T2>
- : IEquatable<ValueTuple<T1, T2>>, IStructuralEquatable, IStructuralComparable, IComparable, IComparable<ValueTuple<T1, T2>>, IValueTupleInternal, ITuple
- {
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2}"/> instance's first component.
- /// </summary>
- public T1 Item1;
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2}"/> instance's second component.
- /// </summary>
- public T2 Item2;
- /// <summary>
- /// Initializes a new instance of the <see cref="ValueTuple{T1, T2}"/> value type.
- /// </summary>
- /// <param name="item1">The value of the tuple's first component.</param>
- /// <param name="item2">The value of the tuple's second component.</param>
- public ValueTuple(T1 item1, T2 item2)
- {
- Item1 = item1;
- Item2 = item2;
- }
- /// <summary>
- /// Returns a value that indicates whether the current <see cref="ValueTuple{T1, T2}"/> instance is equal to a specified object.
- /// </summary>
- /// <param name="obj">The object to compare with this instance.</param>
- /// <returns><see langword="true"/> if the current instance is equal to the specified object; otherwise, <see langword="false"/>.</returns>
- ///
- /// <remarks>
- /// The <paramref name="obj"/> parameter is considered to be equal to the current instance under the following conditions:
- /// <list type="bullet">
- /// <item><description>It is a <see cref="ValueTuple{T1, T2}"/> value type.</description></item>
- /// <item><description>Its components are of the same types as those of the current instance.</description></item>
- /// <item><description>Its components are equal to those of the current instance. Equality is determined by the default object equality comparer for each component.</description></item>
- /// </list>
- /// </remarks>
- public override bool Equals(object obj)
- {
- return obj is ValueTuple<T1, T2> && Equals((ValueTuple<T1, T2>)obj);
- }
- /// <summary>
- /// Returns a value that indicates whether the current <see cref="ValueTuple{T1, T2}"/> instance is equal to a specified <see cref="ValueTuple{T1, T2}"/>.
- /// </summary>
- /// <param name="other">The tuple to compare with this instance.</param>
- /// <returns><see langword="true"/> if the current instance is equal to the specified tuple; otherwise, <see langword="false"/>.</returns>
- /// <remarks>
- /// The <paramref name="other"/> parameter is considered to be equal to the current instance if each of its fields
- /// are equal to that of the current instance, using the default comparer for that field's type.
- /// </remarks>
- public bool Equals(ValueTuple<T1, T2> other)
- {
- return EqualityComparer<T1>.Default.Equals(Item1, other.Item1)
- && EqualityComparer<T2>.Default.Equals(Item2, other.Item2);
- }
- /// <summary>
- /// Returns a value that indicates whether the current <see cref="ValueTuple{T1, T2}"/> instance is equal to a specified object based on a specified comparison method.
- /// </summary>
- /// <param name="other">The object to compare with this instance.</param>
- /// <param name="comparer">An object that defines the method to use to evaluate whether the two objects are equal.</param>
- /// <returns><see langword="true"/> if the current instance is equal to the specified object; otherwise, <see langword="false"/>.</returns>
- ///
- /// <remarks>
- /// This member is an explicit interface member implementation. It can be used only when the
- /// <see cref="ValueTuple{T1, T2}"/> instance is cast to an <see cref="IStructuralEquatable"/> interface.
- ///
- /// The <see cref="IEqualityComparer.Equals"/> implementation is called only if <c>other</c> is not <see langword="null"/>,
- /// and if it can be successfully cast (in C#) or converted (in Visual Basic) to a <see cref="ValueTuple{T1, T2}"/>
- /// whose components are of the same types as those of the current instance. The IStructuralEquatable.Equals(Object, IEqualityComparer) method
- /// first passes the <see cref="Item1"/> values of the <see cref="ValueTuple{T1, T2}"/> objects to be compared to the
- /// <see cref="IEqualityComparer.Equals"/> implementation. If this method call returns <see langword="true"/>, the method is
- /// called again and passed the <see cref="Item2"/> values of the two <see cref="ValueTuple{T1, T2}"/> instances.
- /// </remarks>
- bool IStructuralEquatable.Equals(object other, IEqualityComparer comparer)
- {
- if (other == null || !(other is ValueTuple<T1, T2>)) return false;
- var objTuple = (ValueTuple<T1, T2>)other;
- return comparer.Equals(Item1, objTuple.Item1)
- && comparer.Equals(Item2, objTuple.Item2);
- }
- int IComparable.CompareTo(object other)
- {
- if (other == null) return 1;
- if (!(other is ValueTuple<T1, T2>))
- {
- throw new ArgumentException(SR.Format(SR.ArgumentException_ValueTupleIncorrectType, this.GetType().ToString()), nameof(other));
- }
- return CompareTo((ValueTuple<T1, T2>)other);
- }
- /// <summary>Compares this instance to a specified instance and returns an indication of their relative values.</summary>
- /// <param name="other">An instance to compare.</param>
- /// <returns>
- /// A signed number indicating the relative values of this instance and <paramref name="other"/>.
- /// Returns less than zero if this instance is less than <paramref name="other"/>, zero if this
- /// instance is equal to <paramref name="other"/>, and greater than zero if this instance is greater
- /// than <paramref name="other"/>.
- /// </returns>
- public int CompareTo(ValueTuple<T1, T2> other)
- {
- int c = Comparer<T1>.Default.Compare(Item1, other.Item1);
- if (c != 0) return c;
- return Comparer<T2>.Default.Compare(Item2, other.Item2);
- }
- int IStructuralComparable.CompareTo(object other, IComparer comparer)
- {
- if (other == null) return 1;
- if (!(other is ValueTuple<T1, T2>))
- {
- throw new ArgumentException(SR.Format(SR.ArgumentException_ValueTupleIncorrectType, this.GetType().ToString()), nameof(other));
- }
- var objTuple = (ValueTuple<T1, T2>)other;
- int c = comparer.Compare(Item1, objTuple.Item1);
- if (c != 0) return c;
- return comparer.Compare(Item2, objTuple.Item2);
- }
- /// <summary>
- /// Returns the hash code for the current <see cref="ValueTuple{T1, T2}"/> instance.
- /// </summary>
- /// <returns>A 32-bit signed integer hash code.</returns>
- public override int GetHashCode()
- {
- return ValueTuple.CombineHashCodes(Item1?.GetHashCode() ?? 0,
- Item2?.GetHashCode() ?? 0);
- }
- int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
- {
- return GetHashCodeCore(comparer);
- }
- private int GetHashCodeCore(IEqualityComparer comparer)
- {
- return ValueTuple.CombineHashCodes(comparer.GetHashCode(Item1),
- comparer.GetHashCode(Item2));
- }
- int IValueTupleInternal.GetHashCode(IEqualityComparer comparer)
- {
- return GetHashCodeCore(comparer);
- }
- /// <summary>
- /// Returns a string that represents the value of this <see cref="ValueTuple{T1, T2}"/> instance.
- /// </summary>
- /// <returns>The string representation of this <see cref="ValueTuple{T1, T2}"/> instance.</returns>
- /// <remarks>
- /// The string returned by this method takes the form <c>(Item1, Item2)</c>,
- /// where <c>Item1</c> and <c>Item2</c> represent the values of the <see cref="Item1"/>
- /// and <see cref="Item2"/> fields. If either field value is <see langword="null"/>,
- /// it is represented as <see cref="string.Empty"/>.
- /// </remarks>
- public override string ToString()
- {
- return "(" + Item1?.ToString() + ", " + Item2?.ToString() + ")";
- }
- string IValueTupleInternal.ToStringEnd()
- {
- return Item1?.ToString() + ", " + Item2?.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]
- {
- get
- {
- switch (index)
- {
- case 0:
- return Item1;
- case 1:
- return Item2;
- default:
- throw new IndexOutOfRangeException();
- }
- }
- }
- }
- /// <summary>
- /// Represents a 3-tuple, or triple, as a value type.
- /// </summary>
- /// <typeparam name="T1">The type of the tuple's first component.</typeparam>
- /// <typeparam name="T2">The type of the tuple's second component.</typeparam>
- /// <typeparam name="T3">The type of the tuple's third component.</typeparam>
- [Serializable]
- [StructLayout(LayoutKind.Auto)]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public struct ValueTuple<T1, T2, T3>
- : IEquatable<ValueTuple<T1, T2, T3>>, IStructuralEquatable, IStructuralComparable, IComparable, IComparable<ValueTuple<T1, T2, T3>>, IValueTupleInternal, ITuple
- {
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3}"/> instance's first component.
- /// </summary>
- public T1 Item1;
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3}"/> instance's second component.
- /// </summary>
- public T2 Item2;
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3}"/> instance's third component.
- /// </summary>
- public T3 Item3;
- /// <summary>
- /// Initializes a new instance of the <see cref="ValueTuple{T1, T2, T3}"/> value type.
- /// </summary>
- /// <param name="item1">The value of the tuple's first component.</param>
- /// <param name="item2">The value of the tuple's second component.</param>
- /// <param name="item3">The value of the tuple's third component.</param>
- public ValueTuple(T1 item1, T2 item2, T3 item3)
- {
- Item1 = item1;
- Item2 = item2;
- Item3 = item3;
- }
- /// <summary>
- /// Returns a value that indicates whether the current <see cref="ValueTuple{T1, T2, T3}"/> instance is equal to a specified object.
- /// </summary>
- /// <param name="obj">The object to compare with this instance.</param>
- /// <returns><see langword="true"/> if the current instance is equal to the specified object; otherwise, <see langword="false"/>.</returns>
- /// <remarks>
- /// The <paramref name="obj"/> parameter is considered to be equal to the current instance under the following conditions:
- /// <list type="bullet">
- /// <item><description>It is a <see cref="ValueTuple{T1, T2, T3}"/> value type.</description></item>
- /// <item><description>Its components are of the same types as those of the current instance.</description></item>
- /// <item><description>Its components are equal to those of the current instance. Equality is determined by the default object equality comparer for each component.</description></item>
- /// </list>
- /// </remarks>
- public override bool Equals(object obj)
- {
- return obj is ValueTuple<T1, T2, T3> && Equals((ValueTuple<T1, T2, T3>)obj);
- }
- /// <summary>
- /// Returns a value that indicates whether the current <see cref="ValueTuple{T1, T2, T3}"/>
- /// instance is equal to a specified <see cref="ValueTuple{T1, T2, T3}"/>.
- /// </summary>
- /// <param name="other">The tuple to compare with this instance.</param>
- /// <returns><see langword="true"/> if the current instance is equal to the specified tuple; otherwise, <see langword="false"/>.</returns>
- /// <remarks>
- /// The <paramref name="other"/> parameter is considered to be equal to the current instance if each of its fields
- /// are equal to that of the current instance, using the default comparer for that field's type.
- /// </remarks>
- public bool Equals(ValueTuple<T1, T2, T3> other)
- {
- return EqualityComparer<T1>.Default.Equals(Item1, other.Item1)
- && EqualityComparer<T2>.Default.Equals(Item2, other.Item2)
- && EqualityComparer<T3>.Default.Equals(Item3, other.Item3);
- }
- bool IStructuralEquatable.Equals(object other, IEqualityComparer comparer)
- {
- if (other == null || !(other is ValueTuple<T1, T2, T3>)) return false;
- var objTuple = (ValueTuple<T1, T2, T3>)other;
- return comparer.Equals(Item1, objTuple.Item1)
- && comparer.Equals(Item2, objTuple.Item2)
- && comparer.Equals(Item3, objTuple.Item3);
- }
- int IComparable.CompareTo(object other)
- {
- if (other == null) return 1;
- if (!(other is ValueTuple<T1, T2, T3>))
- {
- throw new ArgumentException(SR.Format(SR.ArgumentException_ValueTupleIncorrectType, this.GetType().ToString()), nameof(other));
- }
- return CompareTo((ValueTuple<T1, T2, T3>)other);
- }
- /// <summary>Compares this instance to a specified instance and returns an indication of their relative values.</summary>
- /// <param name="other">An instance to compare.</param>
- /// <returns>
- /// A signed number indicating the relative values of this instance and <paramref name="other"/>.
- /// Returns less than zero if this instance is less than <paramref name="other"/>, zero if this
- /// instance is equal to <paramref name="other"/>, and greater than zero if this instance is greater
- /// than <paramref name="other"/>.
- /// </returns>
- public int CompareTo(ValueTuple<T1, T2, T3> other)
- {
- int c = Comparer<T1>.Default.Compare(Item1, other.Item1);
- if (c != 0) return c;
- c = Comparer<T2>.Default.Compare(Item2, other.Item2);
- if (c != 0) return c;
- return Comparer<T3>.Default.Compare(Item3, other.Item3);
- }
- int IStructuralComparable.CompareTo(object other, IComparer comparer)
- {
- if (other == null) return 1;
- if (!(other is ValueTuple<T1, T2, T3>))
- {
- throw new ArgumentException(SR.Format(SR.ArgumentException_ValueTupleIncorrectType, this.GetType().ToString()), nameof(other));
- }
- var objTuple = (ValueTuple<T1, T2, T3>)other;
- int c = comparer.Compare(Item1, objTuple.Item1);
- if (c != 0) return c;
- c = comparer.Compare(Item2, objTuple.Item2);
- if (c != 0) return c;
- return comparer.Compare(Item3, objTuple.Item3);
- }
- /// <summary>
- /// Returns the hash code for the current <see cref="ValueTuple{T1, T2, T3}"/> instance.
- /// </summary>
- /// <returns>A 32-bit signed integer hash code.</returns>
- public override int GetHashCode()
- {
- return ValueTuple.CombineHashCodes(Item1?.GetHashCode() ?? 0,
- Item2?.GetHashCode() ?? 0,
- Item3?.GetHashCode() ?? 0);
- }
- int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
- {
- return GetHashCodeCore(comparer);
- }
- private int GetHashCodeCore(IEqualityComparer comparer)
- {
- return ValueTuple.CombineHashCodes(comparer.GetHashCode(Item1),
- comparer.GetHashCode(Item2),
- comparer.GetHashCode(Item3));
- }
- int IValueTupleInternal.GetHashCode(IEqualityComparer comparer)
- {
- return GetHashCodeCore(comparer);
- }
- /// <summary>
- /// Returns a string that represents the value of this <see cref="ValueTuple{T1, T2, T3}"/> instance.
- /// </summary>
- /// <returns>The string representation of this <see cref="ValueTuple{T1, T2, T3}"/> instance.</returns>
- /// <remarks>
- /// The string returned by this method takes the form <c>(Item1, Item2, Item3)</c>.
- /// If any field value is <see langword="null"/>, it is represented as <see cref="string.Empty"/>.
- /// </remarks>
- public override string ToString()
- {
- return "(" + Item1?.ToString() + ", " + Item2?.ToString() + ", " + Item3?.ToString() + ")";
- }
- string IValueTupleInternal.ToStringEnd()
- {
- return Item1?.ToString() + ", " + Item2?.ToString() + ", " + Item3?.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]
- {
- get
- {
- switch (index)
- {
- case 0:
- return Item1;
- case 1:
- return Item2;
- case 2:
- return Item3;
- default:
- throw new IndexOutOfRangeException();
- }
- }
- }
- }
- /// <summary>
- /// Represents a 4-tuple, or quadruple, as a value type.
- /// </summary>
- /// <typeparam name="T1">The type of the tuple's first component.</typeparam>
- /// <typeparam name="T2">The type of the tuple's second component.</typeparam>
- /// <typeparam name="T3">The type of the tuple's third component.</typeparam>
- /// <typeparam name="T4">The type of the tuple's fourth component.</typeparam>
- [Serializable]
- [StructLayout(LayoutKind.Auto)]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public struct ValueTuple<T1, T2, T3, T4>
- : IEquatable<ValueTuple<T1, T2, T3, T4>>, IStructuralEquatable, IStructuralComparable, IComparable, IComparable<ValueTuple<T1, T2, T3, T4>>, IValueTupleInternal, ITuple
- {
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4}"/> instance's first component.
- /// </summary>
- public T1 Item1;
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4}"/> instance's second component.
- /// </summary>
- public T2 Item2;
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4}"/> instance's third component.
- /// </summary>
- public T3 Item3;
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4}"/> instance's fourth component.
- /// </summary>
- public T4 Item4;
- /// <summary>
- /// Initializes a new instance of the <see cref="ValueTuple{T1, T2, T3, T4}"/> value type.
- /// </summary>
- /// <param name="item1">The value of the tuple's first component.</param>
- /// <param name="item2">The value of the tuple's second component.</param>
- /// <param name="item3">The value of the tuple's third component.</param>
- /// <param name="item4">The value of the tuple's fourth component.</param>
- public ValueTuple(T1 item1, T2 item2, T3 item3, T4 item4)
- {
- Item1 = item1;
- Item2 = item2;
- Item3 = item3;
- Item4 = item4;
- }
- /// <summary>
- /// Returns a value that indicates whether the current <see cref="ValueTuple{T1, T2, T3, T4}"/> instance is equal to a specified object.
- /// </summary>
- /// <param name="obj">The object to compare with this instance.</param>
- /// <returns><see langword="true"/> if the current instance is equal to the specified object; otherwise, <see langword="false"/>.</returns>
- /// <remarks>
- /// The <paramref name="obj"/> parameter is considered to be equal to the current instance under the following conditions:
- /// <list type="bullet">
- /// <item><description>It is a <see cref="ValueTuple{T1, T2, T3, T4}"/> value type.</description></item>
- /// <item><description>Its components are of the same types as those of the current instance.</description></item>
- /// <item><description>Its components are equal to those of the current instance. Equality is determined by the default object equality comparer for each component.</description></item>
- /// </list>
- /// </remarks>
- public override bool Equals(object obj)
- {
- return obj is ValueTuple<T1, T2, T3, T4> && Equals((ValueTuple<T1, T2, T3, T4>)obj);
- }
- /// <summary>
- /// Returns a value that indicates whether the current <see cref="ValueTuple{T1, T2, T3, T4}"/>
- /// instance is equal to a specified <see cref="ValueTuple{T1, T2, T3, T4}"/>.
- /// </summary>
- /// <param name="other">The tuple to compare with this instance.</param>
- /// <returns><see langword="true"/> if the current instance is equal to the specified tuple; otherwise, <see langword="false"/>.</returns>
- /// <remarks>
- /// The <paramref name="other"/> parameter is considered to be equal to the current instance if each of its fields
- /// are equal to that of the current instance, using the default comparer for that field's type.
- /// </remarks>
- public bool Equals(ValueTuple<T1, T2, T3, T4> other)
- {
- return EqualityComparer<T1>.Default.Equals(Item1, other.Item1)
- && EqualityComparer<T2>.Default.Equals(Item2, other.Item2)
- && EqualityComparer<T3>.Default.Equals(Item3, other.Item3)
- && EqualityComparer<T4>.Default.Equals(Item4, other.Item4);
- }
- bool IStructuralEquatable.Equals(object other, IEqualityComparer comparer)
- {
- if (other == null || !(other is ValueTuple<T1, T2, T3, T4>)) return false;
- var objTuple = (ValueTuple<T1, T2, T3, T4>)other;
- return comparer.Equals(Item1, objTuple.Item1)
- && comparer.Equals(Item2, objTuple.Item2)
- && comparer.Equals(Item3, objTuple.Item3)
- && comparer.Equals(Item4, objTuple.Item4);
- }
- int IComparable.CompareTo(object other)
- {
- if (other == null) return 1;
- if (!(other is ValueTuple<T1, T2, T3, T4>))
- {
- throw new ArgumentException(SR.Format(SR.ArgumentException_ValueTupleIncorrectType, this.GetType().ToString()), nameof(other));
- }
- return CompareTo((ValueTuple<T1, T2, T3, T4>)other);
- }
- /// <summary>Compares this instance to a specified instance and returns an indication of their relative values.</summary>
- /// <param name="other">An instance to compare.</param>
- /// <returns>
- /// A signed number indicating the relative values of this instance and <paramref name="other"/>.
- /// Returns less than zero if this instance is less than <paramref name="other"/>, zero if this
- /// instance is equal to <paramref name="other"/>, and greater than zero if this instance is greater
- /// than <paramref name="other"/>.
- /// </returns>
- public int CompareTo(ValueTuple<T1, T2, T3, T4> other)
- {
- int c = Comparer<T1>.Default.Compare(Item1, other.Item1);
- if (c != 0) return c;
- c = Comparer<T2>.Default.Compare(Item2, other.Item2);
- if (c != 0) return c;
- c = Comparer<T3>.Default.Compare(Item3, other.Item3);
- if (c != 0) return c;
- return Comparer<T4>.Default.Compare(Item4, other.Item4);
- }
- int IStructuralComparable.CompareTo(object other, IComparer comparer)
- {
- if (other == null) return 1;
- if (!(other is ValueTuple<T1, T2, T3, T4>))
- {
- throw new ArgumentException(SR.Format(SR.ArgumentException_ValueTupleIncorrectType, this.GetType().ToString()), nameof(other));
- }
- var objTuple = (ValueTuple<T1, T2, T3, T4>)other;
- int c = comparer.Compare(Item1, objTuple.Item1);
- if (c != 0) return c;
- c = comparer.Compare(Item2, objTuple.Item2);
- if (c != 0) return c;
- c = comparer.Compare(Item3, objTuple.Item3);
- if (c != 0) return c;
- return comparer.Compare(Item4, objTuple.Item4);
- }
- /// <summary>
- /// Returns the hash code for the current <see cref="ValueTuple{T1, T2, T3, T4}"/> instance.
- /// </summary>
- /// <returns>A 32-bit signed integer hash code.</returns>
- public override int GetHashCode()
- {
- return ValueTuple.CombineHashCodes(Item1?.GetHashCode() ?? 0,
- Item2?.GetHashCode() ?? 0,
- Item3?.GetHashCode() ?? 0,
- Item4?.GetHashCode() ?? 0);
- }
- int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
- {
- return GetHashCodeCore(comparer);
- }
- private int GetHashCodeCore(IEqualityComparer comparer)
- {
- return ValueTuple.CombineHashCodes(comparer.GetHashCode(Item1),
- comparer.GetHashCode(Item2),
- comparer.GetHashCode(Item3),
- comparer.GetHashCode(Item4));
- }
- int IValueTupleInternal.GetHashCode(IEqualityComparer comparer)
- {
- return GetHashCodeCore(comparer);
- }
- /// <summary>
- /// Returns a string that represents the value of this <see cref="ValueTuple{T1, T2, T3, T4}"/> instance.
- /// </summary>
- /// <returns>The string representation of this <see cref="ValueTuple{T1, T2, T3, T4}"/> instance.</returns>
- /// <remarks>
- /// The string returned by this method takes the form <c>(Item1, Item2, Item3, Item4)</c>.
- /// If any field value is <see langword="null"/>, it is represented as <see cref="string.Empty"/>.
- /// </remarks>
- public override string ToString()
- {
- return "(" + Item1?.ToString() + ", " + Item2?.ToString() + ", " + Item3?.ToString() + ", " + Item4?.ToString() + ")";
- }
- string IValueTupleInternal.ToStringEnd()
- {
- return Item1?.ToString() + ", " + Item2?.ToString() + ", " + Item3?.ToString() + ", " + Item4?.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]
- {
- get
- {
- switch (index)
- {
- case 0:
- return Item1;
- case 1:
- return Item2;
- case 2:
- return Item3;
- case 3:
- return Item4;
- default:
- throw new IndexOutOfRangeException();
- }
- }
- }
- }
- /// <summary>
- /// Represents a 5-tuple, or quintuple, as a value type.
- /// </summary>
- /// <typeparam name="T1">The type of the tuple's first component.</typeparam>
- /// <typeparam name="T2">The type of the tuple's second component.</typeparam>
- /// <typeparam name="T3">The type of the tuple's third component.</typeparam>
- /// <typeparam name="T4">The type of the tuple's fourth component.</typeparam>
- /// <typeparam name="T5">The type of the tuple's fifth component.</typeparam>
- [Serializable]
- [StructLayout(LayoutKind.Auto)]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public struct ValueTuple<T1, T2, T3, T4, T5>
- : IEquatable<ValueTuple<T1, T2, T3, T4, T5>>, IStructuralEquatable, IStructuralComparable, IComparable, IComparable<ValueTuple<T1, T2, T3, T4, T5>>, IValueTupleInternal, ITuple
- {
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4, T5}"/> instance's first component.
- /// </summary>
- public T1 Item1;
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4, T5}"/> instance's second component.
- /// </summary>
- public T2 Item2;
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4, T5}"/> instance's third component.
- /// </summary>
- public T3 Item3;
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4, T5}"/> instance's fourth component.
- /// </summary>
- public T4 Item4;
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4, T5}"/> instance's fifth component.
- /// </summary>
- public T5 Item5;
- /// <summary>
- /// Initializes a new instance of the <see cref="ValueTuple{T1, T2, T3, T4, T5}"/> value type.
- /// </summary>
- /// <param name="item1">The value of the tuple's first component.</param>
- /// <param name="item2">The value of the tuple's second component.</param>
- /// <param name="item3">The value of the tuple's third component.</param>
- /// <param name="item4">The value of the tuple's fourth component.</param>
- /// <param name="item5">The value of the tuple's fifth component.</param>
- public ValueTuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5)
- {
- Item1 = item1;
- Item2 = item2;
- Item3 = item3;
- Item4 = item4;
- Item5 = item5;
- }
- /// <summary>
- /// Returns a value that indicates whether the current <see cref="ValueTuple{T1, T2, T3, T4, T5}"/> instance is equal to a specified object.
- /// </summary>
- /// <param name="obj">The object to compare with this instance.</param>
- /// <returns><see langword="true"/> if the current instance is equal to the specified object; otherwise, <see langword="false"/>.</returns>
- /// <remarks>
- /// The <paramref name="obj"/> parameter is considered to be equal to the current instance under the following conditions:
- /// <list type="bullet">
- /// <item><description>It is a <see cref="ValueTuple{T1, T2, T3, T4, T5}"/> value type.</description></item>
- /// <item><description>Its components are of the same types as those of the current instance.</description></item>
- /// <item><description>Its components are equal to those of the current instance. Equality is determined by the default object equality comparer for each component.</description></item>
- /// </list>
- /// </remarks>
- public override bool Equals(object obj)
- {
- return obj is ValueTuple<T1, T2, T3, T4, T5> && Equals((ValueTuple<T1, T2, T3, T4, T5>)obj);
- }
- /// <summary>
- /// Returns a value that indicates whether the current <see cref="ValueTuple{T1, T2, T3, T4, T5}"/>
- /// instance is equal to a specified <see cref="ValueTuple{T1, T2, T3, T4, T5}"/>.
- /// </summary>
- /// <param name="other">The tuple to compare with this instance.</param>
- /// <returns><see langword="true"/> if the current instance is equal to the specified tuple; otherwise, <see langword="false"/>.</returns>
- /// <remarks>
- /// The <paramref name="other"/> parameter is considered to be equal to the current instance if each of its fields
- /// are equal to that of the current instance, using the default comparer for that field's type.
- /// </remarks>
- public bool Equals(ValueTuple<T1, T2, T3, T4, T5> other)
- {
- return EqualityComparer<T1>.Default.Equals(Item1, other.Item1)
- && EqualityComparer<T2>.Default.Equals(Item2, other.Item2)
- && EqualityComparer<T3>.Default.Equals(Item3, other.Item3)
- && EqualityComparer<T4>.Default.Equals(Item4, other.Item4)
- && EqualityComparer<T5>.Default.Equals(Item5, other.Item5);
- }
- bool IStructuralEquatable.Equals(object other, IEqualityComparer comparer)
- {
- if (other == null || !(other is ValueTuple<T1, T2, T3, T4, T5>)) return false;
- var objTuple = (ValueTuple<T1, T2, T3, T4, T5>)other;
- return comparer.Equals(Item1, objTuple.Item1)
- && comparer.Equals(Item2, objTuple.Item2)
- && comparer.Equals(Item3, objTuple.Item3)
- && comparer.Equals(Item4, objTuple.Item4)
- && comparer.Equals(Item5, objTuple.Item5);
- }
- int IComparable.CompareTo(object other)
- {
- if (other == null) return 1;
- if (!(other is ValueTuple<T1, T2, T3, T4, T5>))
- {
- throw new ArgumentException(SR.Format(SR.ArgumentException_ValueTupleIncorrectType, this.GetType().ToString()), nameof(other));
- }
- return CompareTo((ValueTuple<T1, T2, T3, T4, T5>)other);
- }
- /// <summary>Compares this instance to a specified instance and returns an indication of their relative values.</summary>
- /// <param name="other">An instance to compare.</param>
- /// <returns>
- /// A signed number indicating the relative values of this instance and <paramref name="other"/>.
- /// Returns less than zero if this instance is less than <paramref name="other"/>, zero if this
- /// instance is equal to <paramref name="other"/>, and greater than zero if this instance is greater
- /// than <paramref name="other"/>.
- /// </returns>
- public int CompareTo(ValueTuple<T1, T2, T3, T4, T5> other)
- {
- int c = Comparer<T1>.Default.Compare(Item1, other.Item1);
- if (c != 0) return c;
- c = Comparer<T2>.Default.Compare(Item2, other.Item2);
- if (c != 0) return c;
- c = Comparer<T3>.Default.Compare(Item3, other.Item3);
- if (c != 0) return c;
- c = Comparer<T4>.Default.Compare(Item4, other.Item4);
- if (c != 0) return c;
- return Comparer<T5>.Default.Compare(Item5, other.Item5);
- }
- int IStructuralComparable.CompareTo(object other, IComparer comparer)
- {
- if (other == null) return 1;
- if (!(other is ValueTuple<T1, T2, T3, T4, T5>))
- {
- throw new ArgumentException(SR.Format(SR.ArgumentException_ValueTupleIncorrectType, this.GetType().ToString()), nameof(other));
- }
- var objTuple = (ValueTuple<T1, T2, T3, T4, T5>)other;
- int c = comparer.Compare(Item1, objTuple.Item1);
- if (c != 0) return c;
- c = comparer.Compare(Item2, objTuple.Item2);
- if (c != 0) return c;
- c = comparer.Compare(Item3, objTuple.Item3);
- if (c != 0) return c;
- c = comparer.Compare(Item4, objTuple.Item4);
- if (c != 0) return c;
- return comparer.Compare(Item5, objTuple.Item5);
- }
- /// <summary>
- /// Returns the hash code for the current <see cref="ValueTuple{T1, T2, T3, T4, T5}"/> instance.
- /// </summary>
- /// <returns>A 32-bit signed integer hash code.</returns>
- public override int GetHashCode()
- {
- return ValueTuple.CombineHashCodes(Item1?.GetHashCode() ?? 0,
- Item2?.GetHashCode() ?? 0,
- Item3?.GetHashCode() ?? 0,
- Item4?.GetHashCode() ?? 0,
- Item5?.GetHashCode() ?? 0);
- }
- int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
- {
- return GetHashCodeCore(comparer);
- }
- private int GetHashCodeCore(IEqualityComparer comparer)
- {
- return ValueTuple.CombineHashCodes(comparer.GetHashCode(Item1),
- comparer.GetHashCode(Item2),
- comparer.GetHashCode(Item3),
- comparer.GetHashCode(Item4),
- comparer.GetHashCode(Item5));
- }
- int IValueTupleInternal.GetHashCode(IEqualityComparer comparer)
- {
- return GetHashCodeCore(comparer);
- }
- /// <summary>
- /// Returns a string that represents the value of this <see cref="ValueTuple{T1, T2, T3, T4, T5}"/> instance.
- /// </summary>
- /// <returns>The string representation of this <see cref="ValueTuple{T1, T2, T3, T4, T5}"/> instance.</returns>
- /// <remarks>
- /// The string returned by this method takes the form <c>(Item1, Item2, Item3, Item4, Item5)</c>.
- /// If any field value is <see langword="null"/>, it is represented as <see cref="string.Empty"/>.
- /// </remarks>
- public override string ToString()
- {
- return "(" + Item1?.ToString() + ", " + Item2?.ToString() + ", " + Item3?.ToString() + ", " + Item4?.ToString() + ", " + Item5?.ToString() + ")";
- }
- string IValueTupleInternal.ToStringEnd()
- {
- return Item1?.ToString() + ", " + Item2?.ToString() + ", " + Item3?.ToString() + ", " + Item4?.ToString() + ", " + Item5?.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]
- {
- get
- {
- switch (index)
- {
- case 0:
- return Item1;
- case 1:
- return Item2;
- case 2:
- return Item3;
- case 3:
- return Item4;
- case 4:
- return Item5;
- default:
- throw new IndexOutOfRangeException();
- }
- }
- }
- }
- /// <summary>
- /// Represents a 6-tuple, or sixtuple, as a value type.
- /// </summary>
- /// <typeparam name="T1">The type of the tuple's first component.</typeparam>
- /// <typeparam name="T2">The type of the tuple's second component.</typeparam>
- /// <typeparam name="T3">The type of the tuple's third component.</typeparam>
- /// <typeparam name="T4">The type of the tuple's fourth component.</typeparam>
- /// <typeparam name="T5">The type of the tuple's fifth component.</typeparam>
- /// <typeparam name="T6">The type of the tuple's sixth component.</typeparam>
- [Serializable]
- [StructLayout(LayoutKind.Auto)]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public struct ValueTuple<T1, T2, T3, T4, T5, T6>
- : IEquatable<ValueTuple<T1, T2, T3, T4, T5, T6>>, IStructuralEquatable, IStructuralComparable, IComparable, IComparable<ValueTuple<T1, T2, T3, T4, T5, T6>>, IValueTupleInternal, ITuple
- {
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6}"/> instance's first component.
- /// </summary>
- public T1 Item1;
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6}"/> instance's second component.
- /// </summary>
- public T2 Item2;
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6}"/> instance's third component.
- /// </summary>
- public T3 Item3;
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6}"/> instance's fourth component.
- /// </summary>
- public T4 Item4;
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6}"/> instance's fifth component.
- /// </summary>
- public T5 Item5;
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6}"/> instance's sixth component.
- /// </summary>
- public T6 Item6;
- /// <summary>
- /// Initializes a new instance of the <see cref="ValueTuple{T1, T2, T3, T4, T5, T6}"/> value type.
- /// </summary>
- /// <param name="item1">The value of the tuple's first component.</param>
- /// <param name="item2">The value of the tuple's second component.</param>
- /// <param name="item3">The value of the tuple's third component.</param>
- /// <param name="item4">The value of the tuple's fourth component.</param>
- /// <param name="item5">The value of the tuple's fifth component.</param>
- /// <param name="item6">The value of the tuple's sixth component.</param>
- public ValueTuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6)
- {
- Item1 = item1;
- Item2 = item2;
- Item3 = item3;
- Item4 = item4;
- Item5 = item5;
- Item6 = item6;
- }
- /// <summary>
- /// Returns a value that indicates whether the current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6}"/> instance is equal to a specified object.
- /// </summary>
- /// <param name="obj">The object to compare with this instance.</param>
- /// <returns><see langword="true"/> if the current instance is equal to the specified object; otherwise, <see langword="false"/>.</returns>
- /// <remarks>
- /// The <paramref name="obj"/> parameter is considered to be equal to the current instance under the following conditions:
- /// <list type="bullet">
- /// <item><description>It is a <see cref="ValueTuple{T1, T2, T3, T4, T5, T6}"/> value type.</description></item>
- /// <item><description>Its components are of the same types as those of the current instance.</description></item>
- /// <item><description>Its components are equal to those of the current instance. Equality is determined by the default object equality comparer for each component.</description></item>
- /// </list>
- /// </remarks>
- public override bool Equals(object obj)
- {
- return obj is ValueTuple<T1, T2, T3, T4, T5, T6> && Equals((ValueTuple<T1, T2, T3, T4, T5, T6>)obj);
- }
- /// <summary>
- /// Returns a value that indicates whether the current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6}"/>
- /// instance is equal to a specified <see cref="ValueTuple{T1, T2, T3, T4, T5, T6}"/>.
- /// </summary>
- /// <param name="other">The tuple to compare with this instance.</param>
- /// <returns><see langword="true"/> if the current instance is equal to the specified tuple; otherwise, <see langword="false"/>.</returns>
- /// <remarks>
- /// The <paramref name="other"/> parameter is considered to be equal to the current instance if each of its fields
- /// are equal to that of the current instance, using the default comparer for that field's type.
- /// </remarks>
- public bool Equals(ValueTuple<T1, T2, T3, T4, T5, T6> other)
- {
- return EqualityComparer<T1>.Default.Equals(Item1, other.Item1)
- && EqualityComparer<T2>.Default.Equals(Item2, other.Item2)
- && EqualityComparer<T3>.Default.Equals(Item3, other.Item3)
- && EqualityComparer<T4>.Default.Equals(Item4, other.Item4)
- && EqualityComparer<T5>.Default.Equals(Item5, other.Item5)
- && EqualityComparer<T6>.Default.Equals(Item6, other.Item6);
- }
- bool IStructuralEquatable.Equals(object other, IEqualityComparer comparer)
- {
- if (other == null || !(other is ValueTuple<T1, T2, T3, T4, T5, T6>)) return false;
- var objTuple = (ValueTuple<T1, T2, T3, T4, T5, T6>)other;
- return comparer.Equals(Item1, objTuple.Item1)
- && comparer.Equals(Item2, objTuple.Item2)
- && comparer.Equals(Item3, objTuple.Item3)
- && comparer.Equals(Item4, objTuple.Item4)
- && comparer.Equals(Item5, objTuple.Item5)
- && comparer.Equals(Item6, objTuple.Item6);
- }
- int IComparable.CompareTo(object other)
- {
- if (other == null) return 1;
- if (!(other is ValueTuple<T1, T2, T3, T4, T5, T6>))
- {
- throw new ArgumentException(SR.Format(SR.ArgumentException_ValueTupleIncorrectType, this.GetType().ToString()), nameof(other));
- }
- return CompareTo((ValueTuple<T1, T2, T3, T4, T5, T6>)other);
- }
- /// <summary>Compares this instance to a specified instance and returns an indication of their relative values.</summary>
- /// <param name="other">An instance to compare.</param>
- /// <returns>
- /// A signed number indicating the relative values of this instance and <paramref name="other"/>.
- /// Returns less than zero if this instance is less than <paramref name="other"/>, zero if this
- /// instance is equal to <paramref name="other"/>, and greater than zero if this instance is greater
- /// than <paramref name="other"/>.
- /// </returns>
- public int CompareTo(ValueTuple<T1, T2, T3, T4, T5, T6> other)
- {
- int c = Comparer<T1>.Default.Compare(Item1, other.Item1);
- if (c != 0) return c;
- c = Comparer<T2>.Default.Compare(Item2, other.Item2);
- if (c != 0) return c;
- c = Comparer<T3>.Default.Compare(Item3, other.Item3);
- if (c != 0) return c;
- c = Comparer<T4>.Default.Compare(Item4, other.Item4);
- if (c != 0) return c;
- c = Comparer<T5>.Default.Compare(Item5, other.Item5);
- if (c != 0) return c;
- return Comparer<T6>.Default.Compare(Item6, other.Item6);
- }
- int IStructuralComparable.CompareTo(object other, IComparer comparer)
- {
- if (other == null) return 1;
- if (!(other is ValueTuple<T1, T2, T3, T4, T5, T6>))
- {
- throw new ArgumentException(SR.Format(SR.ArgumentException_ValueTupleIncorrectType, this.GetType().ToString()), nameof(other));
- }
- var objTuple = (ValueTuple<T1, T2, T3, T4, T5, T6>)other;
- int c = comparer.Compare(Item1, objTuple.Item1);
- if (c != 0) return c;
- c = comparer.Compare(Item2, objTuple.Item2);
- if (c != 0) return c;
- c = comparer.Compare(Item3, objTuple.Item3);
- if (c != 0) return c;
- c = comparer.Compare(Item4, objTuple.Item4);
- if (c != 0) return c;
- c = comparer.Compare(Item5, objTuple.Item5);
- if (c != 0) return c;
- return comparer.Compare(Item6, objTuple.Item6);
- }
- /// <summary>
- /// Returns the hash code for the current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6}"/> instance.
- /// </summary>
- /// <returns>A 32-bit signed integer hash code.</returns>
- public override int GetHashCode()
- {
- return ValueTuple.CombineHashCodes(Item1?.GetHashCode() ?? 0,
- Item2?.GetHashCode() ?? 0,
- Item3?.GetHashCode() ?? 0,
- Item4?.GetHashCode() ?? 0,
- Item5?.GetHashCode() ?? 0,
- Item6?.GetHashCode() ?? 0);
- }
- int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
- {
- return GetHashCodeCore(comparer);
- }
- private int GetHashCodeCore(IEqualityComparer comparer)
- {
- return ValueTuple.CombineHashCodes(comparer.GetHashCode(Item1),
- comparer.GetHashCode(Item2),
- comparer.GetHashCode(Item3),
- comparer.GetHashCode(Item4),
- comparer.GetHashCode(Item5),
- comparer.GetHashCode(Item6));
- }
- int IValueTupleInternal.GetHashCode(IEqualityComparer comparer)
- {
- return GetHashCodeCore(comparer);
- }
- /// <summary>
- /// Returns a string that represents the value of this <see cref="ValueTuple{T1, T2, T3, T4, T5, T6}"/> instance.
- /// </summary>
- /// <returns>The string representation of this <see cref="ValueTuple{T1, T2, T3, T4, T5, T6}"/> instance.</returns>
- /// <remarks>
- /// The string returned by this method takes the form <c>(Item1, Item2, Item3, Item4, Item5, Item6)</c>.
- /// If any field value is <see langword="null"/>, it is represented as <see cref="string.Empty"/>.
- /// </remarks>
- public override string ToString()
- {
- return "(" + Item1?.ToString() + ", " + Item2?.ToString() + ", " + Item3?.ToString() + ", " + Item4?.ToString() + ", " + Item5?.ToString() + ", " + Item6?.ToString() + ")";
- }
- string IValueTupleInternal.ToStringEnd()
- {
- return Item1?.ToString() + ", " + Item2?.ToString() + ", " + Item3?.ToString() + ", " + Item4?.ToString() + ", " + Item5?.ToString() + ", " + Item6?.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]
- {
- get
- {
- switch (index)
- {
- case 0:
- return Item1;
- case 1:
- return Item2;
- case 2:
- return Item3;
- case 3:
- return Item4;
- case 4:
- return Item5;
- case 5:
- return Item6;
- default:
- throw new IndexOutOfRangeException();
- }
- }
- }
- }
- /// <summary>
- /// Represents a 7-tuple, or sentuple, as a value type.
- /// </summary>
- /// <typeparam name="T1">The type of the tuple's first component.</typeparam>
- /// <typeparam name="T2">The type of the tuple's second component.</typeparam>
- /// <typeparam name="T3">The type of the tuple's third component.</typeparam>
- /// <typeparam name="T4">The type of the tuple's fourth component.</typeparam>
- /// <typeparam name="T5">The type of the tuple's fifth component.</typeparam>
- /// <typeparam name="T6">The type of the tuple's sixth component.</typeparam>
- /// <typeparam name="T7">The type of the tuple's seventh component.</typeparam>
- [Serializable]
- [StructLayout(LayoutKind.Auto)]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public struct ValueTuple<T1, T2, T3, T4, T5, T6, T7>
- : IEquatable<ValueTuple<T1, T2, T3, T4, T5, T6, T7>>, IStructuralEquatable, IStructuralComparable, IComparable, IComparable<ValueTuple<T1, T2, T3, T4, T5, T6, T7>>, IValueTupleInternal, ITuple
- {
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7}"/> instance's first component.
- /// </summary>
- public T1 Item1;
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7}"/> instance's second component.
- /// </summary>
- public T2 Item2;
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7}"/> instance's third component.
- /// </summary>
- public T3 Item3;
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7}"/> instance's fourth component.
- /// </summary>
- public T4 Item4;
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7}"/> instance's fifth component.
- /// </summary>
- public T5 Item5;
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7}"/> instance's sixth component.
- /// </summary>
- public T6 Item6;
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7}"/> instance's seventh component.
- /// </summary>
- public T7 Item7;
- /// <summary>
- /// Initializes a new instance of the <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7}"/> value type.
- /// </summary>
- /// <param name="item1">The value of the tuple's first component.</param>
- /// <param name="item2">The value of the tuple's second component.</param>
- /// <param name="item3">The value of the tuple's third component.</param>
- /// <param name="item4">The value of the tuple's fourth component.</param>
- /// <param name="item5">The value of the tuple's fifth component.</param>
- /// <param name="item6">The value of the tuple's sixth component.</param>
- /// <param name="item7">The value of the tuple's seventh component.</param>
- public ValueTuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7)
- {
- Item1 = item1;
- Item2 = item2;
- Item3 = item3;
- Item4 = item4;
- Item5 = item5;
- Item6 = item6;
- Item7 = item7;
- }
- /// <summary>
- /// Returns a value that indicates whether the current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7}"/> instance is equal to a specified object.
- /// </summary>
- /// <param name="obj">The object to compare with this instance.</param>
- /// <returns><see langword="true"/> if the current instance is equal to the specified object; otherwise, <see langword="false"/>.</returns>
- /// <remarks>
- /// The <paramref name="obj"/> parameter is considered to be equal to the current instance under the following conditions:
- /// <list type="bullet">
- /// <item><description>It is a <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7}"/> value type.</description></item>
- /// <item><description>Its components are of the same types as those of the current instance.</description></item>
- /// <item><description>Its components are equal to those of the current instance. Equality is determined by the default object equality comparer for each component.</description></item>
- /// </list>
- /// </remarks>
- public override bool Equals(object obj)
- {
- return obj is ValueTuple<T1, T2, T3, T4, T5, T6, T7> && Equals((ValueTuple<T1, T2, T3, T4, T5, T6, T7>)obj);
- }
- /// <summary>
- /// Returns a value that indicates whether the current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7}"/>
- /// instance is equal to a specified <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7}"/>.
- /// </summary>
- /// <param name="other">The tuple to compare with this instance.</param>
- /// <returns><see langword="true"/> if the current instance is equal to the specified tuple; otherwise, <see langword="false"/>.</returns>
- /// <remarks>
- /// The <paramref name="other"/> parameter is considered to be equal to the current instance if each of its fields
- /// are equal to that of the current instance, using the default comparer for that field's type.
- /// </remarks>
- public bool Equals(ValueTuple<T1, T2, T3, T4, T5, T6, T7> other)
- {
- return EqualityComparer<T1>.Default.Equals(Item1, other.Item1)
- && EqualityComparer<T2>.Default.Equals(Item2, other.Item2)
- && EqualityComparer<T3>.Default.Equals(Item3, other.Item3)
- && EqualityComparer<T4>.Default.Equals(Item4, other.Item4)
- && EqualityComparer<T5>.Default.Equals(Item5, other.Item5)
- && EqualityComparer<T6>.Default.Equals(Item6, other.Item6)
- && EqualityComparer<T7>.Default.Equals(Item7, other.Item7);
- }
- bool IStructuralEquatable.Equals(object other, IEqualityComparer comparer)
- {
- if (other == null || !(other is ValueTuple<T1, T2, T3, T4, T5, T6, T7>)) return false;
- var objTuple = (ValueTuple<T1, T2, T3, T4, T5, T6, T7>)other;
- return comparer.Equals(Item1, objTuple.Item1)
- && comparer.Equals(Item2, objTuple.Item2)
- && comparer.Equals(Item3, objTuple.Item3)
- && comparer.Equals(Item4, objTuple.Item4)
- && comparer.Equals(Item5, objTuple.Item5)
- && comparer.Equals(Item6, objTuple.Item6)
- && comparer.Equals(Item7, objTuple.Item7);
- }
- int IComparable.CompareTo(object other)
- {
- if (other == null) return 1;
- if (!(other is ValueTuple<T1, T2, T3, T4, T5, T6, T7>))
- {
- throw new ArgumentException(SR.Format(SR.ArgumentException_ValueTupleIncorrectType, this.GetType().ToString()), nameof(other));
- }
- return CompareTo((ValueTuple<T1, T2, T3, T4, T5, T6, T7>)other);
- }
- /// <summary>Compares this instance to a specified instance and returns an indication of their relative values.</summary>
- /// <param name="other">An instance to compare.</param>
- /// <returns>
- /// A signed number indicating the relative values of this instance and <paramref name="other"/>.
- /// Returns less than zero if this instance is less than <paramref name="other"/>, zero if this
- /// instance is equal to <paramref name="other"/>, and greater than zero if this instance is greater
- /// than <paramref name="other"/>.
- /// </returns>
- public int CompareTo(ValueTuple<T1, T2, T3, T4, T5, T6, T7> other)
- {
- int c = Comparer<T1>.Default.Compare(Item1, other.Item1);
- if (c != 0) return c;
- c = Comparer<T2>.Default.Compare(Item2, other.Item2);
- if (c != 0) return c;
- c = Comparer<T3>.Default.Compare(Item3, other.Item3);
- if (c != 0) return c;
- c = Comparer<T4>.Default.Compare(Item4, other.Item4);
- if (c != 0) return c;
- c = Comparer<T5>.Default.Compare(Item5, other.Item5);
- if (c != 0) return c;
- c = Comparer<T6>.Default.Compare(Item6, other.Item6);
- if (c != 0) return c;
- return Comparer<T7>.Default.Compare(Item7, other.Item7);
- }
- int IStructuralComparable.CompareTo(object other, IComparer comparer)
- {
- if (other == null) return 1;
- if (!(other is ValueTuple<T1, T2, T3, T4, T5, T6, T7>))
- {
- throw new ArgumentException(SR.Format(SR.ArgumentException_ValueTupleIncorrectType, this.GetType().ToString()), nameof(other));
- }
- var objTuple = (ValueTuple<T1, T2, T3, T4, T5, T6, T7>)other;
- int c = comparer.Compare(Item1, objTuple.Item1);
- if (c != 0) return c;
- c = comparer.Compare(Item2, objTuple.Item2);
- if (c != 0) return c;
- c = comparer.Compare(Item3, objTuple.Item3);
- if (c != 0) return c;
- c = comparer.Compare(Item4, objTuple.Item4);
- if (c != 0) return c;
- c = comparer.Compare(Item5, objTuple.Item5);
- if (c != 0) return c;
- c = comparer.Compare(Item6, objTuple.Item6);
- if (c != 0) return c;
- return comparer.Compare(Item7, objTuple.Item7);
- }
- /// <summary>
- /// Returns the hash code for the current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7}"/> instance.
- /// </summary>
- /// <returns>A 32-bit signed integer hash code.</returns>
- public override int GetHashCode()
- {
- return ValueTuple.CombineHashCodes(Item1?.GetHashCode() ?? 0,
- Item2?.GetHashCode() ?? 0,
- Item3?.GetHashCode() ?? 0,
- Item4?.GetHashCode() ?? 0,
- Item5?.GetHashCode() ?? 0,
- Item6?.GetHashCode() ?? 0,
- Item7?.GetHashCode() ?? 0);
- }
- int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
- {
- return GetHashCodeCore(comparer);
- }
- private int GetHashCodeCore(IEqualityComparer comparer)
- {
- return ValueTuple.CombineHashCodes(comparer.GetHashCode(Item1),
- comparer.GetHashCode(Item2),
- comparer.GetHashCode(Item3),
- comparer.GetHashCode(Item4),
- comparer.GetHashCode(Item5),
- comparer.GetHashCode(Item6),
- comparer.GetHashCode(Item7));
- }
- int IValueTupleInternal.GetHashCode(IEqualityComparer comparer)
- {
- return GetHashCodeCore(comparer);
- }
- /// <summary>
- /// Returns a string that represents the value of this <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7}"/> instance.
- /// </summary>
- /// <returns>The string representation of this <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7}"/> instance.</returns>
- /// <remarks>
- /// The string returned by this method takes the form <c>(Item1, Item2, Item3, Item4, Item5, Item6, Item7)</c>.
- /// If any field value is <see langword="null"/>, it is represented as <see cref="string.Empty"/>.
- /// </remarks>
- public override string ToString()
- {
- return "(" + Item1?.ToString() + ", " + Item2?.ToString() + ", " + Item3?.ToString() + ", " + Item4?.ToString() + ", " + Item5?.ToString() + ", " + Item6?.ToString() + ", " + Item7?.ToString() + ")";
- }
- string IValueTupleInternal.ToStringEnd()
- {
- return Item1?.ToString() + ", " + Item2?.ToString() + ", " + Item3?.ToString() + ", " + Item4?.ToString() + ", " + Item5?.ToString() + ", " + Item6?.ToString() + ", " + Item7?.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]
- {
- get
- {
- switch (index)
- {
- case 0:
- return Item1;
- case 1:
- return Item2;
- case 2:
- return Item3;
- case 3:
- return Item4;
- case 4:
- return Item5;
- case 5:
- return Item6;
- case 6:
- return Item7;
- default:
- throw new IndexOutOfRangeException();
- }
- }
- }
- }
- /// <summary>
- /// Represents an 8-tuple, or octuple, as a value type.
- /// </summary>
- /// <typeparam name="T1">The type of the tuple's first component.</typeparam>
- /// <typeparam name="T2">The type of the tuple's second component.</typeparam>
- /// <typeparam name="T3">The type of the tuple's third component.</typeparam>
- /// <typeparam name="T4">The type of the tuple's fourth component.</typeparam>
- /// <typeparam name="T5">The type of the tuple's fifth component.</typeparam>
- /// <typeparam name="T6">The type of the tuple's sixth component.</typeparam>
- /// <typeparam name="T7">The type of the tuple's seventh component.</typeparam>
- /// <typeparam name="TRest">The type of the tuple's eighth component.</typeparam>
- [Serializable]
- [StructLayout(LayoutKind.Auto)]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public struct ValueTuple<T1, T2, T3, T4, T5, T6, T7, TRest>
- : IEquatable<ValueTuple<T1, T2, T3, T4, T5, T6, T7, TRest>>, IStructuralEquatable, IStructuralComparable, IComparable, IComparable<ValueTuple<T1, T2, T3, T4, T5, T6, T7, TRest>>, IValueTupleInternal, ITuple
- where TRest : struct
- {
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7, TRest}"/> instance's first component.
- /// </summary>
- public T1 Item1;
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7, TRest}"/> instance's second component.
- /// </summary>
- public T2 Item2;
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7, TRest}"/> instance's third component.
- /// </summary>
- public T3 Item3;
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7, TRest}"/> instance's fourth component.
- /// </summary>
- public T4 Item4;
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7, TRest}"/> instance's fifth component.
- /// </summary>
- public T5 Item5;
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7, TRest}"/> instance's sixth component.
- /// </summary>
- public T6 Item6;
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7, TRest}"/> instance's seventh component.
- /// </summary>
- public T7 Item7;
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7, TRest}"/> instance's eighth component.
- /// </summary>
- public TRest Rest;
- /// <summary>
- /// Initializes a new instance of the <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7, TRest}"/> value type.
- /// </summary>
- /// <param name="item1">The value of the tuple's first component.</param>
- /// <param name="item2">The value of the tuple's second component.</param>
- /// <param name="item3">The value of the tuple's third component.</param>
- /// <param name="item4">The value of the tuple's fourth component.</param>
- /// <param name="item5">The value of the tuple's fifth component.</param>
- /// <param name="item6">The value of the tuple's sixth component.</param>
- /// <param name="item7">The value of the tuple's seventh component.</param>
- /// <param name="rest">The value of the tuple's eight component.</param>
- public ValueTuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7, TRest rest)
- {
- if (!(rest is IValueTupleInternal))
- {
- throw new ArgumentException(SR.ArgumentException_ValueTupleLastArgumentNotAValueTuple);
- }
- Item1 = item1;
- Item2 = item2;
- Item3 = item3;
- Item4 = item4;
- Item5 = item5;
- Item6 = item6;
- Item7 = item7;
- Rest = rest;
- }
- /// <summary>
- /// Returns a value that indicates whether the current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7, TRest}"/> instance is equal to a specified object.
- /// </summary>
- /// <param name="obj">The object to compare with this instance.</param>
- /// <returns><see langword="true"/> if the current instance is equal to the specified object; otherwise, <see langword="false"/>.</returns>
- /// <remarks>
- /// The <paramref name="obj"/> parameter is considered to be equal to the current instance under the following conditions:
- /// <list type="bullet">
- /// <item><description>It is a <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7, TRest}"/> value type.</description></item>
- /// <item><description>Its components are of the same types as those of the current instance.</description></item>
- /// <item><description>Its components are equal to those of the current instance. Equality is determined by the default object equality comparer for each component.</description></item>
- /// </list>
- /// </remarks>
- public override bool Equals(object obj)
- {
- return obj is ValueTuple<T1, T2, T3, T4, T5, T6, T7, TRest> && Equals((ValueTuple<T1, T2, T3, T4, T5, T6, T7, TRest>)obj);
- }
- /// <summary>
- /// Returns a value that indicates whether the current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7, TRest}"/>
- /// instance is equal to a specified <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7, TRest}"/>.
- /// </summary>
- /// <param name="other">The tuple to compare with this instance.</param>
- /// <returns><see langword="true"/> if the current instance is equal to the specified tuple; otherwise, <see langword="false"/>.</returns>
- /// <remarks>
- /// The <paramref name="other"/> parameter is considered to be equal to the current instance if each of its fields
- /// are equal to that of the current instance, using the default comparer for that field's type.
- /// </remarks>
- public bool Equals(ValueTuple<T1, T2, T3, T4, T5, T6, T7, TRest> other)
- {
- return EqualityComparer<T1>.Default.Equals(Item1, other.Item1)
- && EqualityComparer<T2>.Default.Equals(Item2, other.Item2)
- && EqualityComparer<T3>.Default.Equals(Item3, other.Item3)
- && EqualityComparer<T4>.Default.Equals(Item4, other.Item4)
- && EqualityComparer<T5>.Default.Equals(Item5, other.Item5)
- && EqualityComparer<T6>.Default.Equals(Item6, other.Item6)
- && EqualityComparer<T7>.Default.Equals(Item7, other.Item7)
- && EqualityComparer<TRest>.Default.Equals(Rest, other.Rest);
- }
- bool IStructuralEquatable.Equals(object other, IEqualityComparer comparer)
- {
- if (other == null || !(other is ValueTuple<T1, T2, T3, T4, T5, T6, T7, TRest>)) return false;
- var objTuple = (ValueTuple<T1, T2, T3, T4, T5, T6, T7, TRest>)other;
- return comparer.Equals(Item1, objTuple.Item1)
- && comparer.Equals(Item2, objTuple.Item2)
- && comparer.Equals(Item3, objTuple.Item3)
- && comparer.Equals(Item4, objTuple.Item4)
- && comparer.Equals(Item5, objTuple.Item5)
- && comparer.Equals(Item6, objTuple.Item6)
- && comparer.Equals(Item7, objTuple.Item7)
- && comparer.Equals(Rest, objTuple.Rest);
- }
- int IComparable.CompareTo(object other)
- {
- if (other == null) return 1;
- if (!(other is ValueTuple<T1, T2, T3, T4, T5, T6, T7, TRest>))
- {
- throw new ArgumentException(SR.Format(SR.ArgumentException_ValueTupleIncorrectType, this.GetType().ToString()), nameof(other));
- }
- return CompareTo((ValueTuple<T1, T2, T3, T4, T5, T6, T7, TRest>)other);
- }
- /// <summary>Compares this instance to a specified instance and returns an indication of their relative values.</summary>
- /// <param name="other">An instance to compare.</param>
- /// <returns>
- /// A signed number indicating the relative values of this instance and <paramref name="other"/>.
- /// Returns less than zero if this instance is less than <paramref name="other"/>, zero if this
- /// instance is equal to <paramref name="other"/>, and greater than zero if this instance is greater
- /// than <paramref name="other"/>.
- /// </returns>
- public int CompareTo(ValueTuple<T1, T2, T3, T4, T5, T6, T7, TRest> other)
- {
- int c = Comparer<T1>.Default.Compare(Item1, other.Item1);
- if (c != 0) return c;
- c = Comparer<T2>.Default.Compare(Item2, other.Item2);
- if (c != 0) return c;
- c = Comparer<T3>.Default.Compare(Item3, other.Item3);
- if (c != 0) return c;
- c = Comparer<T4>.Default.Compare(Item4, other.Item4);
- if (c != 0) return c;
- c = Comparer<T5>.Default.Compare(Item5, other.Item5);
- if (c != 0) return c;
- c = Comparer<T6>.Default.Compare(Item6, other.Item6);
- if (c != 0) return c;
- c = Comparer<T7>.Default.Compare(Item7, other.Item7);
- if (c != 0) return c;
- return Comparer<TRest>.Default.Compare(Rest, other.Rest);
- }
- int IStructuralComparable.CompareTo(object other, IComparer comparer)
- {
- if (other == null) return 1;
- if (!(other is ValueTuple<T1, T2, T3, T4, T5, T6, T7, TRest>))
- {
- throw new ArgumentException(SR.Format(SR.ArgumentException_ValueTupleIncorrectType, this.GetType().ToString()), nameof(other));
- }
- var objTuple = (ValueTuple<T1, T2, T3, T4, T5, T6, T7, TRest>)other;
- int c = comparer.Compare(Item1, objTuple.Item1);
- if (c != 0) return c;
- c = comparer.Compare(Item2, objTuple.Item2);
- if (c != 0) return c;
- c = comparer.Compare(Item3, objTuple.Item3);
- if (c != 0) return c;
- c = comparer.Compare(Item4, objTuple.Item4);
- if (c != 0) return c;
- c = comparer.Compare(Item5, objTuple.Item5);
- if (c != 0) return c;
- c = comparer.Compare(Item6, objTuple.Item6);
- if (c != 0) return c;
- c = comparer.Compare(Item7, objTuple.Item7);
- if (c != 0) return c;
- return comparer.Compare(Rest, objTuple.Rest);
- }
- /// <summary>
- /// Returns the hash code for the current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7, TRest}"/> instance.
- /// </summary>
- /// <returns>A 32-bit signed integer hash code.</returns>
- public override int GetHashCode()
- {
- // We want to have a limited hash in this case. We'll use the last 8 elements of the tuple
- IValueTupleInternal rest = Rest as IValueTupleInternal;
- if (rest == null)
- {
- return ValueTuple.CombineHashCodes(Item1?.GetHashCode() ?? 0,
- Item2?.GetHashCode() ?? 0,
- Item3?.GetHashCode() ?? 0,
- Item4?.GetHashCode() ?? 0,
- Item5?.GetHashCode() ?? 0,
- Item6?.GetHashCode() ?? 0,
- Item7?.GetHashCode() ?? 0);
- }
- int size = rest.Length;
- if (size >= 8) { return rest.GetHashCode(); }
- // In this case, the rest member has less than 8 elements so we need to combine some our elements with the elements in rest
- int k = 8 - size;
- switch (k)
- {
- case 1:
- return ValueTuple.CombineHashCodes(Item7?.GetHashCode() ?? 0,
- rest.GetHashCode());
- case 2:
- return ValueTuple.CombineHashCodes(Item6?.GetHashCode() ?? 0,
- Item7?.GetHashCode() ?? 0,
- rest.GetHashCode());
- case 3:
- return ValueTuple.CombineHashCodes(Item5?.GetHashCode() ?? 0,
- Item6?.GetHashCode() ?? 0,
- Item7?.GetHashCode() ?? 0,
- rest.GetHashCode());
- case 4:
- return ValueTuple.CombineHashCodes(Item4?.GetHashCode() ?? 0,
- Item5?.GetHashCode() ?? 0,
- Item6?.GetHashCode() ?? 0,
- Item7?.GetHashCode() ?? 0,
- rest.GetHashCode());
- case 5:
- return ValueTuple.CombineHashCodes(Item3?.GetHashCode() ?? 0,
- Item4?.GetHashCode() ?? 0,
- Item5?.GetHashCode() ?? 0,
- Item6?.GetHashCode() ?? 0,
- Item7?.GetHashCode() ?? 0,
- rest.GetHashCode());
- case 6:
- return ValueTuple.CombineHashCodes(Item2?.GetHashCode() ?? 0,
- Item3?.GetHashCode() ?? 0,
- Item4?.GetHashCode() ?? 0,
- Item5?.GetHashCode() ?? 0,
- Item6?.GetHashCode() ?? 0,
- Item7?.GetHashCode() ?? 0,
- rest.GetHashCode());
- case 7:
- case 8:
- return ValueTuple.CombineHashCodes(Item1?.GetHashCode() ?? 0,
- Item2?.GetHashCode() ?? 0,
- Item3?.GetHashCode() ?? 0,
- Item4?.GetHashCode() ?? 0,
- Item5?.GetHashCode() ?? 0,
- Item6?.GetHashCode() ?? 0,
- Item7?.GetHashCode() ?? 0,
- rest.GetHashCode());
- }
- Debug.Fail("Missed all cases for computing ValueTuple hash code");
- return -1;
- }
- int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
- {
- return GetHashCodeCore(comparer);
- }
- private int GetHashCodeCore(IEqualityComparer comparer)
- {
- // We want to have a limited hash in this case. We'll use the last 8 elements of the tuple
- IValueTupleInternal rest = Rest as IValueTupleInternal;
- if (rest == null)
- {
- return ValueTuple.CombineHashCodes(comparer.GetHashCode(Item1), comparer.GetHashCode(Item2), comparer.GetHashCode(Item3),
- comparer.GetHashCode(Item4), comparer.GetHashCode(Item5), comparer.GetHashCode(Item6),
- comparer.GetHashCode(Item7));
- }
- int size = rest.Length;
- if (size >= 8) { return rest.GetHashCode(comparer); }
- // In this case, the rest member has less than 8 elements so we need to combine some our elements with the elements in rest
- int k = 8 - size;
- switch (k)
- {
- case 1:
- return ValueTuple.CombineHashCodes(comparer.GetHashCode(Item7), rest.GetHashCode(comparer));
- case 2:
- return ValueTuple.CombineHashCodes(comparer.GetHashCode(Item6), comparer.GetHashCode(Item7), rest.GetHashCode(comparer));
- case 3:
- return ValueTuple.CombineHashCodes(comparer.GetHashCode(Item5), comparer.GetHashCode(Item6), comparer.GetHashCode(Item7),
- rest.GetHashCode(comparer));
- case 4:
- return ValueTuple.CombineHashCodes(comparer.GetHashCode(Item4), comparer.GetHashCode(Item5), comparer.GetHashCode(Item6),
- comparer.GetHashCode(Item7), rest.GetHashCode(comparer));
- case 5:
- return ValueTuple.CombineHashCodes(comparer.GetHashCode(Item3), comparer.GetHashCode(Item4), comparer.GetHashCode(Item5),
- comparer.GetHashCode(Item6), comparer.GetHashCode(Item7), rest.GetHashCode(comparer));
- case 6:
- return ValueTuple.CombineHashCodes(comparer.GetHashCode(Item2), comparer.GetHashCode(Item3), comparer.GetHashCode(Item4),
- comparer.GetHashCode(Item5), comparer.GetHashCode(Item6), comparer.GetHashCode(Item7),
- rest.GetHashCode(comparer));
- case 7:
- case 8:
- return ValueTuple.CombineHashCodes(comparer.GetHashCode(Item1), comparer.GetHashCode(Item2), comparer.GetHashCode(Item3),
- comparer.GetHashCode(Item4), comparer.GetHashCode(Item5), comparer.GetHashCode(Item6),
- comparer.GetHashCode(Item7), rest.GetHashCode(comparer));
- }
- Debug.Fail("Missed all cases for computing ValueTuple hash code");
- return -1;
- }
- int IValueTupleInternal.GetHashCode(IEqualityComparer comparer)
- {
- return GetHashCodeCore(comparer);
- }
- /// <summary>
- /// Returns a string that represents the value of this <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7, TRest}"/> instance.
- /// </summary>
- /// <returns>The string representation of this <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7, TRest}"/> instance.</returns>
- /// <remarks>
- /// The string returned by this method takes the form <c>(Item1, Item2, Item3, Item4, Item5, Item6, Item7, Rest)</c>.
- /// If any field value is <see langword="null"/>, it is represented as <see cref="string.Empty"/>.
- /// </remarks>
- public override string ToString()
- {
- IValueTupleInternal rest = Rest as IValueTupleInternal;
- if (rest == null)
- {
- return "(" + Item1?.ToString() + ", " + Item2?.ToString() + ", " + Item3?.ToString() + ", " + Item4?.ToString() + ", " + Item5?.ToString() + ", " + Item6?.ToString() + ", " + Item7?.ToString() + ", " + Rest.ToString() + ")";
- }
- else
- {
- return "(" + Item1?.ToString() + ", " + Item2?.ToString() + ", " + Item3?.ToString() + ", " + Item4?.ToString() + ", " + Item5?.ToString() + ", " + Item6?.ToString() + ", " + Item7?.ToString() + ", " + rest.ToStringEnd();
- }
- }
- string IValueTupleInternal.ToStringEnd()
- {
- IValueTupleInternal rest = Rest as IValueTupleInternal;
- if (rest == null)
- {
- return Item1?.ToString() + ", " + Item2?.ToString() + ", " + Item3?.ToString() + ", " + Item4?.ToString() + ", " + Item5?.ToString() + ", " + Item6?.ToString() + ", " + Item7?.ToString() + ", " + Rest.ToString() + ")";
- }
- else
- {
- return Item1?.ToString() + ", " + Item2?.ToString() + ", " + Item3?.ToString() + ", " + Item4?.ToString() + ", " + Item5?.ToString() + ", " + Item6?.ToString() + ", " + Item7?.ToString() + ", " + rest.ToStringEnd();
- }
- }
- /// <summary>
- /// The number of positions in this data structure.
- /// </summary>
- int ITuple.Length
- {
- get
- {
- IValueTupleInternal rest = Rest as IValueTupleInternal;
- return rest == null ? 8 : 7 + rest.Length;
- }
- }
- /// <summary>
- /// Get the element at position <param name="index"/>.
- /// </summary>
- object ITuple.this[int index]
- {
- get
- {
- switch (index)
- {
- case 0:
- return Item1;
- case 1:
- return Item2;
- case 2:
- return Item3;
- case 3:
- return Item4;
- case 4:
- return Item5;
- case 5:
- return Item6;
- case 6:
- return Item7;
- }
- IValueTupleInternal rest = Rest as IValueTupleInternal;
- if (rest == null)
- {
- if (index == 7)
- {
- return Rest;
- }
- throw new IndexOutOfRangeException();
- }
- return rest[index - 7];
- }
- }
- }
- }
|