Skip to content

Update ReferenceEqualityComparer.cs #24728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 10, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions src/Mvc/Mvc.Core/src/ModelBinding/ReferenceEqualityComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
{
internal class ReferenceEqualityComparer : IEqualityComparer<object>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you'd like to go the extra mile, there's a https://github.com/dotnet/runtime/blob/master/src/libraries/Common/src/System/Collections/Generic/ReferenceEqualityComparer.cs#L30 in the runtime now that should be drop-in replacement.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made this change in the browser 🤣

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks worthwhile though

{
private static readonly bool IsMono = Type.GetType("Mono.Runtime") != null;

public static ReferenceEqualityComparer Instance { get; } = new ReferenceEqualityComparer();

public new bool Equals(object x, object y)
Expand All @@ -20,14 +18,6 @@ internal class ReferenceEqualityComparer : IEqualityComparer<object>

public int GetHashCode(object obj)
{
// RuntimeHelpers.GetHashCode sometimes crashes the runtime on Mono 4.0.4
// See: https://github.com/aspnet/External/issues/45
// The workaround here is to just not hash anything, and fall back to an equality check.
if (IsMono)
{
return 0;
}

return RuntimeHelpers.GetHashCode(obj);
}
}
Expand Down