// ----------------------------------------------------------------------------
// Tuple structs for use in .NET Not-Quite-3.5 (e.g. Unity3D).
//
// Used Chapter 3 in http://functional-programming.net/ as a starting point.
//
// Note: .NET 4.0 Tuples are immutable classes so they're *slightly* different.
// ----------------------------------------------------------------------------
using System;
namespace Eppy
{
///
/// Utility class that simplifies cration of tuples by using
/// method calls instead of constructor calls
///
public static class Tuple
{
///
/// Creates a new tuple value with the specified elements. The method
/// can be used without specifying the generic parameters, because C#
/// compiler can usually infer the actual types.
///
/// First element of the tuple
/// Second element of the tuple
/// A newly created tuple
public static Tuple Create(T1 item1, T2 second)
{
return new Tuple(item1, second);
}
///
/// Creates a new tuple value with the specified elements. The method
/// can be used without specifying the generic parameters, because C#
/// compiler can usually infer the actual types.
///
/// First element of the tuple
/// Second element of the tuple
/// Third element of the tuple
/// A newly created tuple
public static Tuple Create(T1 item1, T2 second, T3 third)
{
return new Tuple(item1, second, third);
}
///
/// Creates a new tuple value with the specified elements. The method
/// can be used without specifying the generic parameters, because C#
/// compiler can usually infer the actual types.
///
/// First element of the tuple
/// Second element of the tuple
/// Third element of the tuple
/// Fourth element of the tuple
/// A newly created tuple
public static Tuple Create(T1 item1, T2 second, T3 third, T4 fourth)
{
return new Tuple(item1, second, third, fourth);
}
///
/// Extension method that provides a concise utility for unpacking
/// tuple components into specific out parameters.
///
/// the tuple to unpack from
/// the out parameter that will be assigned tuple.Item1
/// the out parameter that will be assigned tuple.Item2
public static void Unpack(this Tuple tuple, out T1 ref1, out T2 ref2)
{
ref1 = tuple.Item1;
ref2 = tuple.Item2;
}
///
/// Extension method that provides a concise utility for unpacking
/// tuple components into specific out parameters.
///
/// the tuple to unpack from
/// the out parameter that will be assigned tuple.Item1
/// the out parameter that will be assigned tuple.Item2
/// the out parameter that will be assigned tuple.Item3
public static void Unpack(this Tuple tuple, out T1 ref1, out T2 ref2, T3 ref3)
{
ref1 = tuple.Item1;
ref2 = tuple.Item2;
ref3 = tuple.Item3;
}
///
/// Extension method that provides a concise utility for unpacking
/// tuple components into specific out parameters.
///
/// the tuple to unpack from
/// the out parameter that will be assigned tuple.Item1
/// the out parameter that will be assigned tuple.Item2
/// the out parameter that will be assigned tuple.Item3
/// the out parameter that will be assigned tuple.Item4
public static void Unpack(this Tuple tuple, out T1 ref1, out T2 ref2, T3 ref3, T4 ref4)
{
ref1 = tuple.Item1;
ref2 = tuple.Item2;
ref3 = tuple.Item3;
ref4 = tuple.Item4;
}
}
}