Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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 @@ -33,8 +33,7 @@ internal override bool CacheEquals(object? o)
return
o is MdFieldInfo m &&
m.m_tkField == m_tkField &&
m_declaringType.TypeHandle.GetModuleHandle().Equals(
m.m_declaringType.TypeHandle.GetModuleHandle());
m_declaringType.Equals(m.m_declaringType);
}
#endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Reflection.Metadata;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
Expand Down Expand Up @@ -118,6 +119,15 @@ public override string ToString()

return m_toString;
}

public override bool Equals(object? obj) =>
obj == (object)this ||
(MetadataUpdater.IsSupported &&
obj is RuntimeConstructorInfo ci &&
MetadataToken == ci.MetadataToken &&
m_declaringType.Equals(ci.m_declaringType));

public override int GetHashCode() => ValueType.GetHashCodeOfPtr(m_handle);
#endregion

#region ICustomAttributeProvider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection.Metadata;
using RuntimeTypeCache = System.RuntimeType.RuntimeTypeCache;

namespace System.Reflection
Expand Down Expand Up @@ -53,8 +54,7 @@ internal override bool CacheEquals(object? o)
return
o is RuntimeEventInfo m &&
m.m_token == m_token &&
RuntimeTypeHandle.GetModule(m_declaringType).Equals(
RuntimeTypeHandle.GetModule(m.m_declaringType));
m_declaringType.Equals(m.m_declaringType);
}

internal BindingFlags BindingFlags => m_bindingFlags;
Expand All @@ -68,6 +68,13 @@ public override string ToString()

return m_addMethod.GetParametersNoCopy()[0].ParameterType.FormatTypeName() + " " + Name;
}

public override bool Equals(object? obj) =>
obj == (object)this ||
(MetadataUpdater.IsSupported && CacheEquals(obj));

public override int GetHashCode() => MetadataUpdater.IsSupported ?
HashCode.Combine(m_token.GetHashCode(), m_declaringType.GetHashCode()) : base.GetHashCode();
#endregion

#region ICustomAttributeProvider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Generic;
using System.Reflection.Metadata;
using RuntimeTypeCache = System.RuntimeType.RuntimeTypeCache;

namespace System.Reflection
Expand Down Expand Up @@ -46,6 +47,13 @@ internal RuntimeType GetDeclaringTypeInternal()

public override Module Module => GetRuntimeModule();
public override bool IsCollectible => m_declaringType.IsCollectible;

public override bool Equals(object? obj) =>
obj == (object)this ||
(MetadataUpdater.IsSupported && CacheEquals(obj));

public override int GetHashCode() => MetadataUpdater.IsSupported ?
HashCode.Combine(MetadataToken.GetHashCode(), m_declaringType.GetHashCode()) : base.GetHashCode();
#endregion

#region Object Overrides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Reflection.Metadata;
using System.Runtime.CompilerServices;
using System.Security;
using System.Text;
Expand Down Expand Up @@ -157,55 +158,55 @@ public override string ToString()
return m_toString;
}

public override int GetHashCode()
{
// See RuntimeMethodInfo.Equals() below.
if (IsGenericMethod)
return ValueType.GetHashCodeOfPtr(m_handle);
else
return base.GetHashCode();
}
public override int GetHashCode() => ValueType.GetHashCodeOfPtr(m_handle);

public override bool Equals(object? obj)
{
if (!IsGenericMethod)
return obj == (object)this;
if (IsGenericMethod)
{
// We cannot do simple object identity comparisons for generic methods.
// Equals will be called in CerHashTable when RuntimeType+RuntimeTypeCache.GetGenericMethodInfo()
// retrieve items from and insert items into s_methodInstantiations which is a CerHashtable.

// We cannot do simple object identity comparisons for generic methods.
// Equals will be called in CerHashTable when RuntimeType+RuntimeTypeCache.GetGenericMethodInfo()
// retrieve items from and insert items into s_methodInstantiations which is a CerHashtable.
RuntimeMethodInfo? mi = obj as RuntimeMethodInfo;

RuntimeMethodInfo? mi = obj as RuntimeMethodInfo;
if (mi == null || !mi.IsGenericMethod)
return false;

if (mi == null || !mi.IsGenericMethod)
return false;
// now we know that both operands are generic methods

// now we know that both operands are generic methods
IRuntimeMethodInfo handle1 = RuntimeMethodHandle.StripMethodInstantiation(this);
IRuntimeMethodInfo handle2 = RuntimeMethodHandle.StripMethodInstantiation(mi);
if (handle1.Value.Value != handle2.Value.Value)
return false;

IRuntimeMethodInfo handle1 = RuntimeMethodHandle.StripMethodInstantiation(this);
IRuntimeMethodInfo handle2 = RuntimeMethodHandle.StripMethodInstantiation(mi);
if (handle1.Value.Value != handle2.Value.Value)
return false;
Type[] lhs = GetGenericArguments();
Type[] rhs = mi.GetGenericArguments();

Type[] lhs = GetGenericArguments();
Type[] rhs = mi.GetGenericArguments();
if (lhs.Length != rhs.Length)
return false;

if (lhs.Length != rhs.Length)
return false;
for (int i = 0; i < lhs.Length; i++)
{
if (lhs[i] != rhs[i])
return false;
}

for (int i = 0; i < lhs.Length; i++)
{
if (lhs[i] != rhs[i])
if (DeclaringType != mi.DeclaringType)
return false;
}

if (DeclaringType != mi.DeclaringType)
return false;
if (ReflectedType != mi.ReflectedType)
return false;

if (ReflectedType != mi.ReflectedType)
return false;
return true;
}

return obj == (object)this ||
(MetadataUpdater.IsSupported &&
obj is RuntimeMethodInfo m &&
m.MetadataToken == MetadataToken &&
m_declaringType.Equals(m.m_declaringType));

return true;
}
#endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection.Metadata;
using System.Runtime.CompilerServices;
using MdToken = System.Reflection.MetadataToken;

Expand Down Expand Up @@ -496,6 +497,15 @@ public override Type[] GetOptionalCustomModifiers()
m_signature.GetCustomModifiers(PositionImpl + 1, false);
}

public override bool Equals(object? obj) =>
obj == (object)this ||
(MetadataUpdater.IsSupported &&
obj is RuntimeParameterInfo pi &&
m_tkParamDef == pi.m_tkParamDef &&
DefiningMethod.DeclaringType!.Equals(pi.DefiningMethod.DeclaringType));

public override int GetHashCode() => MetadataUpdater.IsSupported ?
HashCode.Combine(m_tkParamDef.GetHashCode(), DefiningMethod.DeclaringType!.GetHashCode()) : base.GetHashCode();
#endregion

#region ICustomAttributeProvider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Reflection.Metadata;
using System.Text;
using RuntimeTypeCache = System.RuntimeType.RuntimeTypeCache;

Expand Down Expand Up @@ -55,8 +56,7 @@ internal override bool CacheEquals(object? o)
return
o is RuntimePropertyInfo m &&
m.m_token == m_token &&
RuntimeTypeHandle.GetModule(m_declaringType).Equals(
RuntimeTypeHandle.GetModule(m.m_declaringType));
m_declaringType.Equals(m.m_declaringType);
}

internal Signature Signature
Expand Down Expand Up @@ -179,6 +179,13 @@ public override IList<CustomAttributeData> GetCustomAttributesData()
public override Module Module => GetRuntimeModule();
internal RuntimeModule GetRuntimeModule() { return m_declaringType.GetRuntimeModule(); }
public override bool IsCollectible => m_declaringType.IsCollectible;

public override bool Equals(object? obj) =>
obj == (object)this ||
(MetadataUpdater.IsSupported && CacheEquals(obj));

public override int GetHashCode() => MetadataUpdater.IsSupported ?
HashCode.Combine(m_token.GetHashCode(), m_declaringType.GetHashCode()) : base.GetHashCode();
#endregion

#region PropertyInfo Overrides
Expand Down
Loading