Created
November 6, 2009 18:29
-
-
Save panesofglass/228163 to your computer and use it in GitHub Desktop.
A set of Tuple classes for pre-.NET 4.0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| namespace Foundation | |
| { | |
| /// <summary> | |
| /// Static extensions for creating tuples. | |
| /// </summary> | |
| public static class Tuple | |
| { | |
| #region methods | |
| /// <summary> | |
| /// Creates a tuple from the provided <paramref name="first"/> and <paramref name="second"/> values. | |
| /// </summary> | |
| /// <typeparam name="T1">The type of the first value.</typeparam> | |
| /// <typeparam name="T2">The type of the second value.</typeparam> | |
| /// <param name="first">The first.</param> | |
| /// <param name="second">The second.</param> | |
| /// <returns>The tuple.</returns> | |
| public static Tuple<T1, T2> Create<T1, T2>(T1 first, T2 second) | |
| { | |
| return new Tuple<T1, T2>(first, second); | |
| } | |
| /// <summary> | |
| /// Creates a tuple from the provided <paramref name="first"/> and <paramref name="second"/> values. | |
| /// </summary> | |
| /// <typeparam name="T1">The type of the first value.</typeparam> | |
| /// <typeparam name="T2">The type of the second value.</typeparam> | |
| /// <typeparam name="T3">The type of the third value.</typeparam> | |
| /// <param name="first">The first value.</param> | |
| /// <param name="second">The second value.</param> | |
| /// <param name="third">The third value.</param> | |
| /// <returns>The tuple.</returns> | |
| public static Tuple<T1, T2, T3> Create<T1, T2, T3>(T1 first, T2 second, T3 third) | |
| { | |
| return new Tuple<T1, T2, T3>(first, second, third); | |
| } | |
| #endregion | |
| } | |
| /// <summary> | |
| /// A tuple of two values. | |
| /// </summary> | |
| /// <typeparam name="T1">The type of the first value.</typeparam> | |
| /// <typeparam name="T2">The type of the second value.</typeparam> | |
| public class Tuple<T1, T2> | |
| { | |
| #region fields | |
| /// <summary> | |
| /// The first value. | |
| /// </summary> | |
| public readonly T1 First; | |
| /// <summary> | |
| /// The second value. | |
| /// </summary> | |
| public readonly T2 Second; | |
| #endregion | |
| #region constructors | |
| /// <summary> | |
| /// Initializes a new instance of the <see cref="Tuple<T1, T2>"/> class. | |
| /// </summary> | |
| /// <param name="first">The first.</param> | |
| /// <param name="second">The second.</param> | |
| public Tuple(T1 first, T2 second) | |
| { | |
| First = first; | |
| Second = second; | |
| } | |
| #endregion | |
| } | |
| /// <summary> | |
| /// A tuple of three values. | |
| /// </summary> | |
| /// <typeparam name="T1">The type of the first value.</typeparam> | |
| /// <typeparam name="T2">The type of the second value.</typeparam> | |
| /// <typeparam name="T3">The type of the third value.</typeparam> | |
| public class Tuple<T1, T2, T3> | |
| { | |
| #region fields | |
| /// <summary> | |
| /// The first value. | |
| /// </summary> | |
| public readonly T1 First; | |
| /// <summary> | |
| /// The second value. | |
| /// </summary> | |
| public readonly T2 Second; | |
| /// <summary> | |
| /// The third value. | |
| /// </summary> | |
| public readonly T3 Third; | |
| #endregion | |
| #region constructors | |
| /// <summary> | |
| /// Initializes a new instance of the <see cref="Tuple<T1, T2, T3>"/> class. | |
| /// </summary> | |
| /// <param name="first">The first.</param> | |
| /// <param name="second">The second.</param> | |
| /// <param name="third">The third.</param> | |
| public Tuple(T1 first, T2 second, T3 third) | |
| { | |
| First = first; | |
| Second = second; | |
| Third = third; | |
| } | |
| #endregion | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment