scripts
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
using System;
|
||||
|
||||
namespace System.Collections.Generic
|
||||
{
|
||||
/// <summary>Provides a base class for implementations of the <see cref="T:System.Collections.Generic.IComparer`1" /> generic interface.</summary>
|
||||
/// <typeparam name="T">The type of objects to compare.</typeparam>
|
||||
/// <filterpriority>1</filterpriority>
|
||||
// Token: 0x020000FB RID: 251
|
||||
[Serializable]
|
||||
public abstract class Comparer<T> : IComparer<T>, IComparer
|
||||
{
|
||||
// Token: 0x06000C67 RID: 3175 RVA: 0x00038470 File Offset: 0x00036670
|
||||
static Comparer()
|
||||
{
|
||||
if (typeof(IComparable<T>).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
Comparer<T>._default = (Comparer<T>)Activator.CreateInstance(typeof(GenericComparer<>).MakeGenericType(new Type[] { typeof(T) }));
|
||||
}
|
||||
else
|
||||
{
|
||||
Comparer<T>._default = new Comparer<T>.DefaultComparer();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other.</summary>
|
||||
/// <returns>A signed integer that indicates the relative values of <paramref name="x" /> and <paramref name="y" />, as shown in the following table.Value Meaning Less than zero<paramref name="x" /> is less than <paramref name="y" />.Zero<paramref name="x" /> equals <paramref name="y" />.Greater than zero<paramref name="x" /> is greater than <paramref name="y" />.</returns>
|
||||
/// <param name="x">The first object to compare.</param>
|
||||
/// <param name="y">The second object to compare.</param>
|
||||
/// <exception cref="T:System.ArgumentException">
|
||||
/// <paramref name="x" /> or <paramref name="y" /> is of a type that cannot be cast to type <paramref name="T" />.-or-<paramref name="x" /> and <paramref name="y" /> do not implement either the <see cref="T:System.IComparable`1" /> generic interface or the <see cref="T:System.IComparable" /> interface.</exception>
|
||||
// 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();
|
||||
}
|
||||
|
||||
/// <summary>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.</summary>
|
||||
/// <returns>A signed integer that indicates the relative values of <paramref name="x" /> and <paramref name="y" />, as shown in the following table.Value Meaning Less than zero <paramref name="x" /> is less than <paramref name="y" />.Zero <paramref name="x" /> equals <paramref name="y" />.Greater than zero <paramref name="x" /> is greater than <paramref name="y" />.</returns>
|
||||
/// <param name="x">The first object to compare.</param>
|
||||
/// <param name="y">The second object to compare.</param>
|
||||
/// <exception cref="T:System.ArgumentException">Type <paramref name="T" /> does not implement either the <see cref="T:System.IComparable`1" /> generic interface or the <see cref="T:System.IComparable" /> interface.</exception>
|
||||
// Token: 0x06000C69 RID: 3177
|
||||
public abstract int Compare(T x, T y);
|
||||
|
||||
/// <summary>Returns a default sort order comparer for the type specified by the generic argument.</summary>
|
||||
/// <returns>An object that inherits <see cref="T:System.Collections.Generic.Comparer`1" /> and serves as a sort order comparer for type <paramref name="T" />.</returns>
|
||||
// Token: 0x170001C7 RID: 455
|
||||
// (get) Token: 0x06000C6A RID: 3178 RVA: 0x00038534 File Offset: 0x00036734
|
||||
public static Comparer<T> Default
|
||||
{
|
||||
get
|
||||
{
|
||||
return Comparer<T>._default;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x0400035F RID: 863
|
||||
private static readonly Comparer<T> _default;
|
||||
|
||||
// Token: 0x020000FC RID: 252
|
||||
private sealed class DefaultComparer : Comparer<T>
|
||||
{
|
||||
// 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<T>)
|
||||
{
|
||||
return ((IComparable<T>)((object)x)).CompareTo(y);
|
||||
}
|
||||
if (x is IComparable)
|
||||
{
|
||||
return ((IComparable)((object)x)).CompareTo(y);
|
||||
}
|
||||
throw new ArgumentException("does not implement right interface");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user