static EqualityComparer() { var t = typeof(T); if (t == typeof(string)) { _default = (EqualityComparer <T>)(object) new InternalStringComparer(); return; } if (t == typeof(int)) { _default = (EqualityComparer <T>)(object) new IntEqualityComparer(); return; } if (t.IsEnum && Enum.GetUnderlyingType(t) == typeof(int)) { _default = new EnumIntEqualityComparer <T> (); return; } if (typeof(IEquatable <T>).IsAssignableFrom(t)) { _default = (EqualityComparer <T>)Activator.CreateInstance(typeof(GenericEqualityComparer <>).MakeGenericType(t)); } else { _default = new DefaultComparer <T> (); } }
static EqualityComparer() { if (typeof(IEquatable <T>).IsAssignableFrom(typeof(T))) { _default = (EqualityComparer <T>)Activator.CreateInstance(typeof(GenericEqualityComparer <>).MakeGenericType(typeof(T))); } else { _default = new DefaultComparer(); } }
static Comparer() { if (typeof(T).IsValueType) { Default = new DefaultComparerValueType(); } else { Default = new DefaultComparer(); } }
static Comparer() { #if NOT_PFX if (typeof(IComparable <T>).IsAssignableFrom(typeof(T))) { _default = (Comparer <T>)Activator.CreateInstance(typeof(GenericComparer <>).MakeGenericType(typeof(T))); } else #endif _default = new DefaultComparer(); }
static EqualityComparer() { if (typeof(T) == typeof(string)) { _default = (EqualityComparer <T>)(object) new InternalStringComparer(); return; } if (typeof(IEquatable <T>).IsAssignableFrom(typeof(T))) { _default = (EqualityComparer <T>)Activator.CreateInstance(typeof(GenericEqualityComparer <>).MakeGenericType(typeof(T))); } else { _default = new DefaultComparer(); } }
static EqualityComparer() { // Need to use the GenericEqualityComparer, but can't because // cannot instantiate the type yet, because T needs to implement IEquatable<T> Default = new DefaultComparer(); }