You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
82 lines
2.0 KiB
82 lines
2.0 KiB
5 years ago
|
#if NET20 || NET30 || NET35 || !NET_4_6
|
||
|
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Globalization;
|
||
|
|
||
|
namespace System
|
||
|
{
|
||
|
[Serializable]
|
||
|
public class Tuple<T1> : IStructuralEquatable, IStructuralComparable, IComparable
|
||
|
{
|
||
|
private readonly T1 _item1;
|
||
|
|
||
|
public Tuple(T1 item1)
|
||
|
{
|
||
|
_item1 = item1;
|
||
|
}
|
||
|
|
||
|
public T1 Item1
|
||
|
{
|
||
|
get { return _item1; }
|
||
|
}
|
||
|
|
||
|
public override bool Equals(object obj)
|
||
|
{
|
||
|
return ((IStructuralEquatable)this).Equals(obj, EqualityComparer<object>.Default);
|
||
|
}
|
||
|
|
||
|
public override int GetHashCode()
|
||
|
{
|
||
|
return ((IStructuralEquatable)this).GetHashCode(EqualityComparer<object>.Default);
|
||
|
}
|
||
|
|
||
|
int IStructuralComparable.CompareTo(object other, IComparer comparer)
|
||
|
{
|
||
|
return CompareTo(other, comparer);
|
||
|
}
|
||
|
|
||
|
bool IStructuralEquatable.Equals(object other, IEqualityComparer comparer)
|
||
|
{
|
||
|
var tuple = other as Tuple<T1>;
|
||
|
return tuple != null && comparer.Equals(_item1, tuple._item1);
|
||
|
}
|
||
|
|
||
|
int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
|
||
|
{
|
||
|
return comparer.GetHashCode(_item1);
|
||
|
}
|
||
|
|
||
|
int IComparable.CompareTo(object obj)
|
||
|
{
|
||
|
return CompareTo(obj, Comparer<object>.Default);
|
||
|
}
|
||
|
|
||
|
public override string ToString()
|
||
|
{
|
||
|
return string.Format(CultureInfo.InvariantCulture, "({0})", _item1);
|
||
|
}
|
||
|
|
||
|
private int CompareTo(object other, IComparer comparer)
|
||
|
{
|
||
|
if (other == null)
|
||
|
{
|
||
|
return 1;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
var tuple = other as Tuple<T1>;
|
||
|
if (tuple == null)
|
||
|
{
|
||
|
throw new ArgumentException("other");
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return comparer.Compare(_item1, tuple._item1);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#endif
|