Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,14 @@ internal RuntimeParameterInfo(MethodInfo owner, string? name, Type parameterType
#endregion

#region Public Methods
public override bool Equals(object? obj) =>
obj is RuntimeParameterInfo other &&
PositionImpl == other.PositionImpl &&
MemberImpl.Equals(other.MemberImpl);

public override int GetHashCode() =>
HashCode.Combine(MemberImpl, PositionImpl);

public override Type ParameterType
{
get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,42 @@ public void GetMembers_MultipleCalls_ClearCache_ReflectionCacheTestsType()
}, options);
}

[ActiveIssue("https://github.com/dotnet/runtime/issues/50978", TestRuntimes.Mono)]
[ConditionalFact(typeof(ReflectionCacheTests), nameof(IsMetadataUpdateAndRemoteExecutorSupported))]
public void GetParameters_ClearCache_EqualsAndHashCodeEqual()
{
RemoteInvokeOptions options = new RemoteInvokeOptions();
options.StartInfo.EnvironmentVariables.Add("DOTNET_MODIFIABLE_ASSEMBLIES", "debug");

using RemoteInvokeHandle remoteHandle = RemoteExecutor.Invoke(() =>
{
Action<Type[]> clearCache = GetClearCacheMethod();
MethodInfo method1 = s_type.GetMethod(nameof(Method));
ParameterInfo parameter1 = method1.GetParameters()[0];
var valuesByParameter = new System.Collections.Generic.Dictionary<ParameterInfo, int>
{
[parameter1] = 1
};

clearCache(new[] { typeof(ReflectionCacheTests) });

MethodInfo method2 = s_type.GetMethod(nameof(Method));
ParameterInfo parameter2 = method2.GetParameters()[0];

Assert.NotSame(method1, method2);
Assert.True(method1.Equals(method2));
Assert.NotSame(parameter1, parameter2);

// Parameters for equal members at the same position should remain equal
// after Hot Reload clears the reflection cache, including as dictionary keys.
Assert.True(parameter1.Equals(parameter2));
Assert.True(parameter2.Equals(parameter1));
Assert.Equal(parameter1.GetHashCode(), parameter2.GetHashCode());
Comment thread
MichalStrehovsky marked this conversation as resolved.
Assert.True(valuesByParameter.TryGetValue(parameter2, out int value));
Assert.Equal(1, value);
}, options);
}

private static void AssertNotSameSameButEqualAndHashCodeEqual(object o1, object o2)
{
// After the cache cleared the references of the same members will be Not Same.
Expand Down
Loading