diff options
Diffstat (limited to 'src/mscorlib/src/System/Collections/Generic/EqualityComparer.cs')
-rw-r--r-- | src/mscorlib/src/System/Collections/Generic/EqualityComparer.cs | 153 |
1 files changed, 4 insertions, 149 deletions
diff --git a/src/mscorlib/src/System/Collections/Generic/EqualityComparer.cs b/src/mscorlib/src/System/Collections/Generic/EqualityComparer.cs index 3731114119..0f9259d2f3 100644 --- a/src/mscorlib/src/System/Collections/Generic/EqualityComparer.cs +++ b/src/mscorlib/src/System/Collections/Generic/EqualityComparer.cs @@ -6,7 +6,6 @@ using System; using System.Collections; using System.Collections.Generic; using System.Security; -using System.Runtime.Serialization; namespace System.Collections.Generic { @@ -367,7 +366,7 @@ namespace System.Collections.Generic } [Serializable] - internal class EnumEqualityComparer<T> : EqualityComparer<T>, ISerializable where T : struct + internal class EnumEqualityComparer<T> : EqualityComparer<T> where T : struct { [Pure] public override bool Equals(T x, T y) { @@ -384,16 +383,6 @@ namespace System.Collections.Generic public EnumEqualityComparer() { } - // This is used by the serialization engine. - protected EnumEqualityComparer(SerializationInfo information, StreamingContext context) { } - - public void GetObjectData(SerializationInfo info, StreamingContext context) { - // For back-compat we need to serialize the comparers for enums with underlying types other than int as ObjectEqualityComparer - if (Type.GetTypeCode(Enum.GetUnderlyingType(typeof(T))) != TypeCode.Int32) { - info.SetType(typeof(ObjectEqualityComparer<T>)); - } - } - // Equals method for the comparer itself. public override bool Equals(Object obj) => obj != null && GetType() == obj.GetType(); @@ -427,13 +416,10 @@ namespace System.Collections.Generic } [Serializable] - internal sealed class SByteEnumEqualityComparer<T> : EnumEqualityComparer<T>, ISerializable where T : struct + internal sealed class SByteEnumEqualityComparer<T> : EnumEqualityComparer<T> where T : struct { public SByteEnumEqualityComparer() { } - // This is used by the serialization engine. - public SByteEnumEqualityComparer(SerializationInfo information, StreamingContext context) { } - [Pure] public override int GetHashCode(T obj) { int x_final = System.Runtime.CompilerServices.JitHelpers.UnsafeEnumCast(obj); @@ -442,13 +428,10 @@ namespace System.Collections.Generic } [Serializable] - internal sealed class ShortEnumEqualityComparer<T> : EnumEqualityComparer<T>, ISerializable where T : struct + internal sealed class ShortEnumEqualityComparer<T> : EnumEqualityComparer<T> where T : struct { public ShortEnumEqualityComparer() { } - // This is used by the serialization engine. - public ShortEnumEqualityComparer(SerializationInfo information, StreamingContext context) { } - [Pure] public override int GetHashCode(T obj) { int x_final = System.Runtime.CompilerServices.JitHelpers.UnsafeEnumCast(obj); @@ -457,7 +440,7 @@ namespace System.Collections.Generic } [Serializable] - internal sealed class LongEnumEqualityComparer<T> : EqualityComparer<T>, ISerializable where T : struct + internal sealed class LongEnumEqualityComparer<T> : EqualityComparer<T> where T : struct { [Pure] public override bool Equals(T x, T y) { @@ -481,16 +464,6 @@ namespace System.Collections.Generic public LongEnumEqualityComparer() { } - // This is used by the serialization engine. - public LongEnumEqualityComparer(SerializationInfo information, StreamingContext context) { } - - public void GetObjectData(SerializationInfo info, StreamingContext context) - { - // The LongEnumEqualityComparer does not exist on 4.0 so we need to serialize this comparer as ObjectEqualityComparer - // to allow for roundtrip between 4.0 and 4.5. - info.SetType(typeof(ObjectEqualityComparer<T>)); - } - internal override int IndexOf(T[] array, T value, int startIndex, int count) { long toFind = JitHelpers.UnsafeEnumCastLong(value); @@ -515,122 +488,4 @@ namespace System.Collections.Generic return -1; } } - -#if FEATURE_RANDOMIZED_STRING_HASHING - // This type is not serializeable by design. It does not exist in previous versions and will be removed - // Once we move the framework to using secure hashing by default. - internal sealed class RandomizedStringEqualityComparer : IEqualityComparer<String>, IEqualityComparer, IWellKnownStringEqualityComparer - { - private long _entropy; - - public RandomizedStringEqualityComparer() { - _entropy = HashHelpers.GetEntropy(); - } - - public new bool Equals(object x, object y) { - if (x == y) return true; - if (x == null || y == null) return false; - if ((x is string) && (y is string)) return Equals((string)x, (string)y); - ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidArgumentForComparison); - return false; - } - - [Pure] - public bool Equals(string x, string y) { - if (x != null) { - if (y != null) return x.Equals(y); - return false; - } - if (y != null) return false; - return true; - } - - [Pure] - public int GetHashCode(String obj) { - if(obj == null) return 0; - return String.InternalMarvin32HashString(obj, obj.Length, _entropy); - } - - [Pure] - public int GetHashCode(Object obj) { - if(obj == null) return 0; - - string sObj = obj as string; - if(sObj != null) return String.InternalMarvin32HashString(sObj, sObj.Length, _entropy); - - return obj.GetHashCode(); - } - - // Equals method for the comparer itself. - public override bool Equals(Object obj) { - RandomizedStringEqualityComparer comparer = obj as RandomizedStringEqualityComparer; - return (comparer != null) && (this._entropy == comparer._entropy); - } - - public override int GetHashCode() { - return (this.GetType().GetHashCode() ^ ((int) (_entropy & 0x7FFFFFFF))); - } - - - IEqualityComparer IWellKnownStringEqualityComparer.GetRandomizedEqualityComparer() { - return new RandomizedStringEqualityComparer(); - } - - // We want to serialize the old comparer. - IEqualityComparer IWellKnownStringEqualityComparer.GetEqualityComparerForSerialization() { - return EqualityComparer<string>.Default; - } - } - - // This type is not serializeable by design. It does not exist in previous versions and will be removed - // Once we move the framework to using secure hashing by default. - internal sealed class RandomizedObjectEqualityComparer : IEqualityComparer, IWellKnownStringEqualityComparer - { - private long _entropy; - - public RandomizedObjectEqualityComparer() { - _entropy = HashHelpers.GetEntropy(); - } - - [Pure] - public new bool Equals(Object x, Object y) { - if (x != null) { - if (y != null) return x.Equals(y); - return false; - } - if (y != null) return false; - return true; - } - - [Pure] - public int GetHashCode(Object obj) { - if(obj == null) return 0; - - string sObj = obj as string; - if(sObj != null) return String.InternalMarvin32HashString(sObj, sObj.Length, _entropy); - - return obj.GetHashCode(); - } - - // Equals method for the comparer itself. - public override bool Equals(Object obj){ - RandomizedObjectEqualityComparer comparer = obj as RandomizedObjectEqualityComparer; - return (comparer != null) && (this._entropy == comparer._entropy); - } - - public override int GetHashCode() { - return (this.GetType().GetHashCode() ^ ((int) (_entropy & 0x7FFFFFFF))); - } - - IEqualityComparer IWellKnownStringEqualityComparer.GetRandomizedEqualityComparer() { - return new RandomizedObjectEqualityComparer(); - } - - // We want to serialize the old comparer, which in this case was null. - IEqualityComparer IWellKnownStringEqualityComparer.GetEqualityComparerForSerialization() { - return null; - } - } -#endif } - |