-
-
Notifications
You must be signed in to change notification settings - Fork 744
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed cycle detection in AnyType and ObjectToDictionaryConverter (#7262)
- Loading branch information
Showing
10 changed files
with
327 additions
and
11 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
src/HotChocolate/Core/src/Types/Properties/TypeResources.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/HotChocolate/Core/src/Types/Utilities/ReferenceEqualityComparer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#nullable enable | ||
|
||
#if NETSTANDARD2_0 | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace HotChocolate.Utilities; | ||
|
||
/// <summary> | ||
/// An <see cref="IEqualityComparer{Object}"/> that uses reference equality (<see cref="object.ReferenceEquals(object?, object?)"/>) | ||
/// instead of value equality (<see cref="object.Equals(object?)"/>) when comparing two object instances. | ||
/// </summary> | ||
/// <remarks> | ||
/// The <see cref="ReferenceEqualityComparer"/> type cannot be instantiated. Instead, use the <see cref="Instance"/> property | ||
/// to access the singleton instance of this type. | ||
/// </remarks> | ||
internal sealed class ReferenceEqualityComparer : IEqualityComparer<object?>, IEqualityComparer | ||
{ | ||
private ReferenceEqualityComparer() { } | ||
|
||
/// <summary> | ||
/// Gets the singleton <see cref="ReferenceEqualityComparer"/> instance. | ||
/// </summary> | ||
public static ReferenceEqualityComparer Instance { get; } = new ReferenceEqualityComparer(); | ||
|
||
/// <summary> | ||
/// Determines whether two object references refer to the same object instance. | ||
/// </summary> | ||
/// <param name="x">The first object to compare.</param> | ||
/// <param name="y">The second object to compare.</param> | ||
/// <returns> | ||
/// <see langword="true"/> if both <paramref name="x"/> and <paramref name="y"/> refer to the same object instance | ||
/// or if both are <see langword="null"/>; otherwise, <see langword="false"/>. | ||
/// </returns> | ||
/// <remarks> | ||
/// This API is a wrapper around <see cref="object.ReferenceEquals(object?, object?)"/>. | ||
/// It is not necessarily equivalent to calling <see cref="object.Equals(object?, object?)"/>. | ||
/// </remarks> | ||
public new bool Equals(object? x, object? y) => ReferenceEquals(x, y); | ||
|
||
/// <summary> | ||
/// Returns a hash code for the specified object. The returned hash code is based on the object | ||
/// identity, not on the contents of the object. | ||
/// </summary> | ||
/// <param name="obj">The object for which to retrieve the hash code.</param> | ||
/// <returns>A hash code for the identity of <paramref name="obj"/>.</returns> | ||
/// <remarks> | ||
/// This API is a wrapper around <see cref="RuntimeHelpers.GetHashCode(object)"/>. | ||
/// It is not necessarily equivalent to calling <see cref="object.GetHashCode()"/>. | ||
/// </remarks> | ||
public int GetHashCode(object? obj) | ||
{ | ||
// Depending on target framework, RuntimeHelpers.GetHashCode might not be annotated | ||
// with the proper nullability attribute. We'll suppress any warning that might | ||
// result. | ||
return RuntimeHelpers.GetHashCode(obj!); | ||
} | ||
} | ||
#endif |
Oops, something went wrong.