You've already forked linux-packaging-mono
Imported Upstream version 6.4.0.137
Former-commit-id: 943baa9f16a098c33e129777827f3a9d20da00d6
This commit is contained in:
parent
e9207cf623
commit
ef583813eb
@ -0,0 +1,46 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace System.Collections.Generic
|
||||
{
|
||||
partial class Comparer<T>
|
||||
{
|
||||
static volatile Comparer<T> defaultComparer;
|
||||
|
||||
public static Comparer<T> Default {
|
||||
get {
|
||||
Comparer<T> comparer = defaultComparer;
|
||||
if (comparer == null) {
|
||||
comparer = CreateComparer();
|
||||
defaultComparer = comparer;
|
||||
}
|
||||
return comparer;
|
||||
}
|
||||
}
|
||||
|
||||
static Comparer<T> CreateComparer() {
|
||||
RuntimeType t = (RuntimeType)typeof(T);
|
||||
|
||||
if (typeof(IComparable<T>).IsAssignableFrom(t))
|
||||
return (Comparer<T>)RuntimeType.CreateInstanceForAnotherGenericParameter (typeof(GenericComparer<>), t);
|
||||
|
||||
// If T is a Nullable<U> where U implements IComparable<U> return a NullableComparer<U>
|
||||
if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(Nullable<>)) {
|
||||
RuntimeType u = (RuntimeType)t.GetGenericArguments()[0];
|
||||
if (typeof(IComparable<>).MakeGenericType (u).IsAssignableFrom (u))
|
||||
return (Comparer<T>)RuntimeType.CreateInstanceForAnotherGenericParameter (typeof(NullableComparer<>), u);
|
||||
}
|
||||
|
||||
if (t.IsEnum)
|
||||
return (Comparer<T>)RuntimeType.CreateInstanceForAnotherGenericParameter (typeof(EnumComparer<>), t);
|
||||
|
||||
// Otherwise return an ObjectComparer<T>
|
||||
return new ObjectComparer<T> ();
|
||||
}
|
||||
}
|
||||
|
||||
partial class EnumComparer<T>
|
||||
{
|
||||
[MethodImpl (MethodImplOptions.AggressiveInlining)]
|
||||
public override int Compare (T x, T y) => JitHelpers.EnumCompareTo (x, y);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user