using System;
namespace System.Collections.Generic
{
/// Provides a base class for implementations of the generic interface.
/// The type of objects to compare.
/// 1
// Token: 0x020000FB RID: 251
[Serializable]
public abstract class Comparer : IComparer, IComparer
{
// Token: 0x06000C67 RID: 3175 RVA: 0x00038470 File Offset: 0x00036670
static Comparer()
{
if (typeof(IComparable).IsAssignableFrom(typeof(T)))
{
Comparer._default = (Comparer)Activator.CreateInstance(typeof(GenericComparer<>).MakeGenericType(new Type[] { typeof(T) }));
}
else
{
Comparer._default = new Comparer.DefaultComparer();
}
}
/// Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other.
/// A signed integer that indicates the relative values of and , as shown in the following table.Value Meaning Less than zero is less than .Zero equals .Greater than zero is greater than .
/// The first object to compare.
/// The second object to compare.
///
/// or is of a type that cannot be cast to type .-or- and do not implement either the generic interface or the interface.
// Token: 0x06000C68 RID: 3176 RVA: 0x000384DC File Offset: 0x000366DC
int IComparer.Compare(object x, object y)
{
if (x == null)
{
return (y != null) ? (-1) : 0;
}
if (y == null)
{
return 1;
}
if (x is T && y is T)
{
return this.Compare((T)((object)x), (T)((object)y));
}
throw new ArgumentException();
}
/// When overridden in a derived class, performs a comparison of two objects of the same type and returns a value indicating whether one object is less than, equal to, or greater than the other.
/// A signed integer that indicates the relative values of and , as shown in the following table.Value Meaning Less than zero is less than .Zero equals .Greater than zero is greater than .
/// The first object to compare.
/// The second object to compare.
/// Type does not implement either the generic interface or the interface.
// Token: 0x06000C69 RID: 3177
public abstract int Compare(T x, T y);
/// Returns a default sort order comparer for the type specified by the generic argument.
/// An object that inherits and serves as a sort order comparer for type .
// Token: 0x170001C7 RID: 455
// (get) Token: 0x06000C6A RID: 3178 RVA: 0x00038534 File Offset: 0x00036734
public static Comparer Default
{
get
{
return Comparer._default;
}
}
// Token: 0x0400035F RID: 863
private static readonly Comparer _default;
// Token: 0x020000FC RID: 252
private sealed class DefaultComparer : Comparer
{
// Token: 0x06000C6C RID: 3180 RVA: 0x00038544 File Offset: 0x00036744
public override int Compare(T x, T y)
{
if (x == null)
{
return (y != null) ? (-1) : 0;
}
if (y == null)
{
return 1;
}
if (x is IComparable)
{
return ((IComparable)((object)x)).CompareTo(y);
}
if (x is IComparable)
{
return ((IComparable)((object)x)).CompareTo(y);
}
throw new ArgumentException("does not implement right interface");
}
}
}
}