9 [TypeDependency(
"System.Collections.Generic.ObjectEqualityComparer`1")]
10 [__DynamicallyInvokable]
17 [__DynamicallyInvokable]
20 [__DynamicallyInvokable]
24 if (equalityComparer ==
null)
26 equalityComparer = (defaultComparer = CreateComparer());
28 return equalityComparer;
32 [SecuritySafeCritical]
35 RuntimeType runtimeType = (RuntimeType)typeof(T);
36 if (runtimeType == typeof(
byte))
42 return (EqualityComparer<T>)
RuntimeTypeHandle.CreateInstanceForAnotherGenericParameter((RuntimeType)typeof(GenericEqualityComparer<int>), runtimeType);
44 if (runtimeType.IsGenericType && runtimeType.GetGenericTypeDefinition() == typeof(
Nullable<>))
46 RuntimeType runtimeType2 = (RuntimeType)runtimeType.GetGenericArguments()[0];
47 if (typeof(
IEquatable<>).MakeGenericType(runtimeType2).IsAssignableFrom(runtimeType2))
49 return (EqualityComparer<T>)
RuntimeTypeHandle.CreateInstanceForAnotherGenericParameter((RuntimeType)typeof(NullableEqualityComparer<int>), runtimeType2);
52 if (runtimeType.IsEnum)
54 switch (
Type.GetTypeCode(
Enum.GetUnderlyingType(runtimeType)))
57 return (EqualityComparer<T>)RuntimeTypeHandle.CreateInstanceForAnotherGenericParameter((RuntimeType)typeof(ShortEnumEqualityComparer<short>), runtimeType);
59 return (EqualityComparer<T>)RuntimeTypeHandle.CreateInstanceForAnotherGenericParameter((RuntimeType)typeof(SByteEnumEqualityComparer<sbyte>), runtimeType);
64 return (EqualityComparer<T>)RuntimeTypeHandle.CreateInstanceForAnotherGenericParameter((RuntimeType)typeof(EnumEqualityComparer<int>), runtimeType);
67 return (EqualityComparer<T>)RuntimeTypeHandle.CreateInstanceForAnotherGenericParameter((RuntimeType)typeof(LongEnumEqualityComparer<long>), runtimeType);
70 return new ObjectEqualityComparer<T>();
78 [__DynamicallyInvokable]
79 public abstract bool Equals(T x, T y);
85 [__DynamicallyInvokable]
88 internal virtual int IndexOf(T[] array, T value,
int startIndex,
int count)
90 int num = startIndex + count;
91 for (
int i = startIndex; i < num; i++)
93 if (
Equals(array[i], value))
101 internal virtual int LastIndexOf(T[] array, T value,
int startIndex,
int count)
103 int num = startIndex - count + 1;
104 for (
int num2 = startIndex; num2 >= num; num2--)
106 if (
Equals(array[num2], value))
119 [__DynamicallyInvokable]
120 int IEqualityComparer.GetHashCode(
object obj)
130 ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidArgumentForComparison);
141 [__DynamicallyInvokable]
142 bool IEqualityComparer.Equals(
object x,
object y)
148 if (x ==
null || y ==
null)
152 if (x is T && y is T)
154 return Equals((T)x, (T)y);
156 ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidArgumentForComparison);
161 [__DynamicallyInvokable]
Provides a base class for implementations of the T:System.Collections.Generic.IEqualityComparer`1 gen...
Defines methods to support the comparison of objects for equality.
TypeCode
Specifies the type of an object.
Represents a type using an internal metadata token.
Represents a value type that can be assigned null.
static EqualityComparer< T > Default
Returns a default equality comparer for the type specified by the generic argument.
EqualityComparer()
Initializes a new instance of the T:System.Collections.Generic.EqualityComparer`1 class.
Attribute can be applied to an enumeration.
Defines a generalized method that a value type or class implements to create a type-specific method f...
Specifies that the class can be serialized.
abstract int GetHashCode(T obj)
When overridden in a derived class, serves as a hash function for the specified object for hashing al...
abstract bool Equals(T x, T y)
When overridden in a derived class, determines whether two objects of type T are equal.