Skip to content
This repository has been archived by the owner on Nov 1, 2020. It is now read-only.

Commit

Permalink
Fix CoreRT build breaks
Browse files Browse the repository at this point in the history
  • Loading branch information
jkotas committed Dec 30, 2018
1 parent cdc6fcb commit dfb9267
Show file tree
Hide file tree
Showing 11 changed files with 123 additions and 575 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.


using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;

namespace System.Collections.Generic
{
[Serializable]
[System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
[TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
public abstract partial class Comparer<T> : IComparer, IComparer<T>
{
// public static Comparer<T> Default is runtime-specific
Expand Down Expand Up @@ -56,7 +54,7 @@ public override int Compare(T x, T y)
// means another generic instantiation, which can be costly esp.
// for value types.
[Serializable]
[System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
[TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
// Needs to be public to support binary serialization compatibility
public sealed partial class GenericComparer<T> : Comparer<T> where T : IComparable<T>
{
Expand All @@ -80,7 +78,7 @@ public override int GetHashCode() =>
}

[Serializable]
[System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
[TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
// Needs to be public to support binary serialization compatibility
public sealed partial class NullableComparer<T> : Comparer<T?> where T : struct, IComparable<T>
{
Expand All @@ -104,7 +102,7 @@ public override int GetHashCode() =>
}

[Serializable]
[System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
[TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
// Needs to be public to support binary serialization compatibility
public sealed partial class ObjectComparer<T> : Comparer<T>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Runtime;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
using System.Diagnostics;

namespace System.Collections.Generic
{
[Serializable]
[System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
[TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
public abstract partial class EqualityComparer<T> : IEqualityComparer, IEqualityComparer<T>
{
// public static EqualityComparer<T> Default is runtime-specific
Expand Down Expand Up @@ -39,7 +37,7 @@ bool IEqualityComparer.Equals(object x, object y)
// The methods in this class look identical to the inherited methods, but the calls
// to Equal bind to IEquatable<T>.Equals(T) instead of Object.Equals(Object)
[Serializable]
[System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
[TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
// Needs to be public to support binary serialization compatibility
public sealed partial class GenericEqualityComparer<T> : EqualityComparer<T> where T : IEquatable<T>
{
Expand Down Expand Up @@ -69,7 +67,7 @@ public override int GetHashCode() =>
}

[Serializable]
[System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
[TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
// Needs to be public to support binary serialization compatibility
public sealed partial class NullableEqualityComparer<T> : EqualityComparer<T?> where T : struct, IEquatable<T>
{
Expand Down Expand Up @@ -97,7 +95,7 @@ public override int GetHashCode() =>
}

[Serializable]
[System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
[TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
// Needs to be public to support binary serialization compatibility
public sealed partial class ObjectEqualityComparer<T> : EqualityComparer<T>
{
Expand Down Expand Up @@ -125,7 +123,7 @@ public override int GetHashCode() =>
}

[Serializable]
[System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
[TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
// Needs to be public to support binary serialization compatibility
public sealed partial class ByteEqualityComparer : EqualityComparer<byte>
{
Expand All @@ -150,7 +148,7 @@ public override int GetHashCode() =>
}

[Serializable]
[System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
[TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
// Needs to be public to support binary serialization compatibility
public sealed partial class EnumEqualityComparer<T> : EqualityComparer<T>, ISerializable where T : struct, Enum
{
Expand Down
3 changes: 3 additions & 0 deletions src/System.Private.CoreLib/shared/System/ThrowHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,8 @@ private static string GetResourceString(ExceptionResource resource)
{
switch (resource)
{
case ExceptionResource.Argument_InvalidArgumentForComparison:
return SR.Argument_InvalidArgumentForComparison;
case ExceptionResource.ArgumentOutOfRange_Index:
return SR.ArgumentOutOfRange_Index;
case ExceptionResource.ArgumentOutOfRange_Count:
Expand Down Expand Up @@ -572,6 +574,7 @@ internal enum ExceptionArgument
//
internal enum ExceptionResource
{
Argument_InvalidArgumentForComparison,
ArgumentOutOfRange_Index,
ArgumentOutOfRange_Count,
Arg_ArrayPlusOffTooSmall,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
using System.Collections.Generic;
using System.Runtime;

using Internal.IntrinsicSupport;
using Internal.Runtime.Augments;

namespace Internal.IntrinsicSupport
Expand Down Expand Up @@ -113,112 +112,5 @@ private static Comparer<T> GetKnownObjectComparer<T>()
{
return new ObjectComparer<T>();
}

// This routine emulates System.Collection.Comparer.Default.Compare(), which lives in the System.Collections.NonGenerics contract.
// To avoid adding a reference to that contract just for this hack, we'll replicate the implementation here.
internal static int CompareObjects(object x, object y)
{
if (x == y)
return 0;

if (x == null)
return -1;

if (y == null)
return 1;

{
// System.Collection.Comparer.Default.Compare() compares strings using the CurrentCulture.
string sx = x as string;
string sy = y as string;
if (sx != null && sy != null)
return string.Compare(sx, sy, StringComparison.CurrentCulture);
}

IComparable ix = x as IComparable;
if (ix != null)
return ix.CompareTo(y);

IComparable iy = y as IComparable;
if (iy != null)
return -iy.CompareTo(x);

throw new ArgumentException(SR.Argument_ImplementIComparable);
}
}
}

namespace System.Collections.Generic
{
//-----------------------------------------------------------------------
// Implementations of EqualityComparer<T> for the various possible scenarios
// Because these are serializable, they must not be renamed
//-----------------------------------------------------------------------
[Serializable]
[System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
public sealed class GenericComparer<T> : Comparer<T> where T : IComparable<T>
{
public sealed override int Compare(T x, T y)
{
if (x != null)
{
if (y != null)
return x.CompareTo(y);

return 1;
}

if (y != null)
return -1;

return 0;
}

// Equals method for the comparer itself.
public sealed override bool Equals(object obj) => obj != null && GetType() == obj.GetType();

public sealed override int GetHashCode() => GetType().GetHashCode();
}

[Serializable]
[System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
public sealed class NullableComparer<T> : Comparer<Nullable<T>> where T : struct, IComparable<T>
{
public sealed override int Compare(Nullable<T> x, Nullable<T> y)
{
if (x.HasValue)
{
if (y.HasValue)
return x.Value.CompareTo(y.Value);

return 1;
}

if (y.HasValue)
return -1;

return 0;
}

// Equals method for the comparer itself.
public sealed override bool Equals(object obj) => obj != null && GetType() == obj.GetType();

public sealed override int GetHashCode() => GetType().GetHashCode();
}

[Serializable]
[System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
public sealed class ObjectComparer<T> : Comparer<T>
{
public sealed override int Compare(T x, T y)
{
return ComparerHelpers.CompareObjects(x, y);
}

// Equals method for the comparer itself.
public sealed override bool Equals(object obj) => obj != null && GetType() == obj.GetType();

public sealed override int GetHashCode() => GetType().GetHashCode();
}
}

Loading

0 comments on commit dfb9267

Please sign in to comment.