From: Jan Kotas Date: Tue, 31 Oct 2017 00:18:09 +0000 (-0700) Subject: Fix build warning (#14751) X-Git-Tag: accepted/tizen/base/20180629.140029~749 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2d3d03bd777278c47d0026062315700fa1e8c4d0;p=platform%2Fupstream%2Fcoreclr.git Fix build warning (#14751) --- diff --git a/src/mscorlib/src/System/Collections/Generic/EqualityComparer.cs b/src/mscorlib/src/System/Collections/Generic/EqualityComparer.cs index aad7c75..072f6dd 100644 --- a/src/mscorlib/src/System/Collections/Generic/EqualityComparer.cs +++ b/src/mscorlib/src/System/Collections/Generic/EqualityComparer.cs @@ -365,6 +365,19 @@ namespace System.Collections.Generic [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] internal sealed class EnumEqualityComparer : EqualityComparer, ISerializable where T : struct { + internal EnumEqualityComparer() { } + + // This is used by the serialization engine. + private 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)); + } + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public override bool Equals(T x, T y) { @@ -379,11 +392,6 @@ namespace System.Collections.Generic return obj.GetHashCode(); } - public EnumEqualityComparer() { } - - // This is used by the serialization engine. - protected EnumEqualityComparer(SerializationInfo information, StreamingContext context) { } - // Equals method for the comparer itself. public override bool Equals(Object obj) => obj != null && GetType() == obj.GetType(); @@ -414,19 +422,23 @@ namespace System.Collections.Generic } return -1; } - - 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)); - } - } } [Serializable] internal sealed class LongEnumEqualityComparer : EqualityComparer, ISerializable where T : struct { + internal LongEnumEqualityComparer() { } + + // This is used by the serialization engine. + private 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)); + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public override bool Equals(T x, T y) { @@ -448,8 +460,6 @@ namespace System.Collections.Generic public override int GetHashCode() => GetType().GetHashCode(); - public LongEnumEqualityComparer() { } - internal override int IndexOf(T[] array, T value, int startIndex, int count) { long toFind = JitHelpers.UnsafeEnumCastLong(value); @@ -473,15 +483,5 @@ namespace System.Collections.Generic } return -1; } - - // 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)); - } } }