Skip to content
This repository was archived by the owner on Nov 1, 2020. It is now read-only.
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 @@ -30,6 +30,8 @@ public virtual Module Module
}
}

public virtual bool HasSameMetadataDefinitionAs(MemberInfo other) { throw NotImplemented.ByDesign; }

public abstract bool IsDefined(Type attributeType, bool inherit);
public abstract object[] GetCustomAttributes(bool inherit);
public abstract object[] GetCustomAttributes(Type attributeType, bool inherit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
<Compile Include="System\Reflection\Runtime\General\ReflectionCoreCallbacksImplementation.cs" />
<Compile Include="System\Reflection\Runtime\General\Dispensers.cs" />
<Compile Include="System\Reflection\Runtime\General\Helpers.cs" />
<Compile Include="System\Reflection\Runtime\General\IRuntimeMemberInfoWithNoMetadataDefinition.cs" />
<Compile Include="System\Reflection\Runtime\General\LegacyCustomAttributeApis.cs" />
<Compile Include="System\Reflection\Runtime\General\ListBuilder.cs" />
<Compile Include="System\Reflection\Runtime\General\MetadataReaderExtensions.NativeFormat.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,21 @@ public sealed override IEnumerable<CustomAttributeData> CustomAttributes
}
}

public sealed override bool HasSameMetadataDefinitionAs(MemberInfo other)
{
if (other == null)
throw new ArgumentNullException(nameof(other));

EcmaFormatRuntimeEventInfo otherEvent = other as EcmaFormatRuntimeEventInfo;
if (otherEvent == null)
return false;
if (!(_reader == otherEvent._reader))
return false;
if (!(_eventHandle.Equals(otherEvent._eventHandle)))
return false;
return true;
}

public sealed override bool Equals(Object obj)
{
EcmaFormatRuntimeEventInfo other = obj as EcmaFormatRuntimeEventInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,23 @@ public sealed override IEnumerable<CustomAttributeData> CustomAttributes
}
}

public sealed override bool HasSameMetadataDefinitionAs(MemberInfo other)
{
if (other == null)
throw new ArgumentNullException(nameof(other));

NativeFormatRuntimeEventInfo otherEvent = other as NativeFormatRuntimeEventInfo;
if (otherEvent == null)
return false;
if (!(_reader == otherEvent._reader))
return false;
if (!(_eventHandle.Equals(otherEvent._eventHandle)))
return false;
if (!(_definingTypeInfo.Equals(otherEvent._definingTypeInfo)))
return false;
return true;
}

public sealed override bool Equals(Object obj)
{
NativeFormatRuntimeEventInfo other = obj as NativeFormatRuntimeEventInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public sealed override MethodInfo[] GetOtherMethods(bool nonPublic)
throw new PlatformNotSupportedException();
}

public abstract override bool HasSameMetadataDefinitionAs(MemberInfo other);

public sealed override Module Module
{
get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,21 @@ public sealed override String ToString()
}
}

public sealed override bool HasSameMetadataDefinitionAs(MemberInfo other)
{
if (other == null)
throw new ArgumentNullException(nameof(other));

EcmaFormatRuntimeFieldInfo otherField = other as EcmaFormatRuntimeFieldInfo;
if (otherField == null)
return false;
if (!(_reader == otherField._reader))
return false;
if (!(_fieldHandle.Equals(otherField._fieldHandle)))
return false;
return true;
}

public sealed override bool Equals(Object obj)
{
EcmaFormatRuntimeFieldInfo other = obj as EcmaFormatRuntimeFieldInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,23 @@ public sealed override String ToString()
return (new QTypeDefRefOrSpec(_reader, typeHandle).FormatTypeName(typeContext)) + " " + this.Name;
}

public sealed override bool HasSameMetadataDefinitionAs(MemberInfo other)
{
if (other == null)
throw new ArgumentNullException(nameof(other));

NativeFormatRuntimeFieldInfo otherField = other as NativeFormatRuntimeFieldInfo;
if (otherField == null)
return false;
if (!(_reader == otherField._reader))
return false;
if (!(_fieldHandle.Equals(otherField._fieldHandle)))
return false;
if (!(_definingTypeInfo.Equals(otherField._definingTypeInfo)))
return false;
return true;
}

public sealed override bool Equals(Object obj)
{
NativeFormatRuntimeFieldInfo other = obj as NativeFormatRuntimeFieldInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ public sealed override object GetValueDirect(TypedReference obj)
return fieldAccessor.GetFieldDirect(obj);
}

public abstract override bool HasSameMetadataDefinitionAs(MemberInfo other);

public sealed override Module Module
{
get
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

namespace System.Reflection.Runtime.General
{
// This interface's presence on a MemberInfo testates that
//
// 1. The MemberInfo implemented by Reflection.Core
// 2. Is to be lumped into the "no metadata token" group for the purposes
// of the HasSameMetadataDefinitionAs() api.
//
internal interface IRuntimeMemberInfoWithNoMetadataDefinition
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,15 @@ public MethodDefinitionHandle MethodHandle
}
}

public bool HasSameMetadataDefinitionAs(EcmaFormatMethodCommon other)
{
if (!(_reader == other._reader))
return false;
if (!(_methodHandle.Equals(other._methodHandle)))
return false;
return true;
}

public override bool Equals(Object obj)
{
if (!(obj is EcmaFormatMethodCommon))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ internal interface IRuntimeMethodCommon<TRuntimeMethodCommon> where TRuntimeMeth

bool IsGenericMethodDefinition { get; }

bool HasSameMetadataDefinitionAs(TRuntimeMethodCommon other);

TRuntimeMethodCommon RuntimeMethodCommonOfUninstantiatedMethod { get; }

RuntimeTypeInfo[] GetGenericTypeParametersWithSpecifiedOwningMethod(RuntimeNamedMethodInfo<TRuntimeMethodCommon> owningMethod);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,17 @@ public MethodHandle MethodHandle
}
}

public bool HasSameMetadataDefinitionAs(NativeFormatMethodCommon other)
{
if (!(_reader == other._reader))
return false;
if (!(_methodHandle.Equals(other._methodHandle)))
return false;
if (!(_definingTypeInfo.Equals(other._definingTypeInfo)))
return false;
return true;
}

public override bool Equals(Object obj)
{
if (!(obj is NativeFormatMethodCommon))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ private RuntimeCLSIDNullaryConstructorInfo(RuntimeCLSIDTypeInfo declaringType)
public sealed override IEnumerable<CustomAttributeData> CustomAttributes => Empty<CustomAttributeData>.Enumerable;
public sealed override Type DeclaringType => _declaringType;

public sealed override bool HasSameMetadataDefinitionAs(MemberInfo other)
{
if (other == null)
throw new ArgumentNullException(nameof(other));

// This logic is written to match CoreCLR's behavior.
return other is RuntimeCLSIDNullaryConstructorInfo;
}

public sealed override bool Equals(object obj)
{
RuntimeCLSIDNullaryConstructorInfo other = obj as RuntimeCLSIDNullaryConstructorInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ public sealed override IEnumerable<CustomAttributeData> CustomAttributes
}
}

public sealed override bool HasSameMetadataDefinitionAs(MemberInfo other)
{
return _genericMethodDefinition.HasSameMetadataDefinitionAs(other);
}

public sealed override bool Equals(Object obj)
{
RuntimeConstructedGenericMethodInfo other = obj as RuntimeConstructedGenericMethodInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ public sealed override ParameterInfo[] GetParametersNoCopy()
return RuntimeParameters;
}

public abstract override bool HasSameMetadataDefinitionAs(MemberInfo other);

public abstract override object Invoke(BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture);

[DebuggerGuidedStepThrough]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ private RuntimeDummyMethodInfo() { }
public sealed override bool IsConstructedGenericMethod { get { throw NotImplemented.ByDesign; } }
public sealed override bool IsGenericMethod { get { throw NotImplemented.ByDesign; } }
public sealed override bool IsGenericMethodDefinition { get { throw NotImplemented.ByDesign; } }
public sealed override bool HasSameMetadataDefinitionAs(MemberInfo other) { throw NotImplemented.ByDesign; }
public sealed override MethodImplAttributes MethodImplementationFlags { get { throw NotImplemented.ByDesign; } }
public sealed override Module Module { get { throw NotImplemented.ByDesign; } }
public sealed override MethodBase MetadataDefinitionMethod { get { throw NotImplemented.ByDesign; } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ public sealed override ParameterInfo[] GetParametersNoCopy()
return RuntimeParameters;
}

public abstract override bool HasSameMetadataDefinitionAs(MemberInfo other);

[DebuggerGuidedStepThroughAttribute]
public sealed override object Invoke(object obj, BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,23 @@ public sealed override String ToString()
return ComputeToString(this);
}

public sealed override bool HasSameMetadataDefinitionAs(MemberInfo other)
{
if (other == null)
throw new ArgumentNullException(nameof(other));

// Do not rewrite as a call to IsConstructedGenericMethod - we haven't yet established that "other" is a runtime-implemented member yet!
RuntimeConstructedGenericMethodInfo otherConstructedGenericMethod = other as RuntimeConstructedGenericMethodInfo;
if (otherConstructedGenericMethod != null)
other = otherConstructedGenericMethod.GetGenericMethodDefinition();

RuntimeNamedMethodInfo<TRuntimeMethodCommon> otherMethod = other as RuntimeNamedMethodInfo<TRuntimeMethodCommon>;
if (otherMethod == null)
return false;

return _common.HasSameMetadataDefinitionAs(otherMethod._common);
}

public sealed override bool Equals(Object obj)
{
RuntimeNamedMethodInfo<TRuntimeMethodCommon> other = obj as RuntimeNamedMethodInfo<TRuntimeMethodCommon>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,17 @@ public sealed override int MetadataToken
}
}

public sealed override bool HasSameMetadataDefinitionAs(MemberInfo other)
{
if (other == null)
throw new ArgumentNullException(nameof(other));

RuntimePlainConstructorInfo<TRuntimeMethodCommon> otherConstructor = other as RuntimePlainConstructorInfo<TRuntimeMethodCommon>;
if (otherConstructor == null)
return false;
return _common.HasSameMetadataDefinitionAs(otherConstructor._common);
}

public sealed override bool Equals(Object obj)
{
RuntimePlainConstructorInfo<TRuntimeMethodCommon> other = obj as RuntimePlainConstructorInfo<TRuntimeMethodCommon>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ namespace System.Reflection.Runtime.MethodInfos
//
// The runtime's implementation of constructors exposed on array types.
//
internal sealed partial class RuntimeSyntheticConstructorInfo : RuntimeConstructorInfo
internal sealed partial class RuntimeSyntheticConstructorInfo : RuntimeConstructorInfo, IRuntimeMemberInfoWithNoMetadataDefinition
{
private RuntimeSyntheticConstructorInfo(SyntheticMethodId syntheticMethodId, RuntimeTypeInfo declaringType, RuntimeTypeInfo[] runtimeParameterTypes, InvokerOptions options, Func<Object, Object[], Object> invoker)
{
Debug.Assert(declaringType.IsArray);

_syntheticMethodId = syntheticMethodId;
_declaringType = declaringType;
_options = options;
Expand Down Expand Up @@ -104,6 +106,15 @@ public sealed override String Name
}
}

public sealed override bool HasSameMetadataDefinitionAs(MemberInfo other)
{
if (other == null)
throw new ArgumentNullException(nameof(other));

// This logic is written to match CoreCLR's behavior.
return other is ConstructorInfo && other is IRuntimeMemberInfoWithNoMetadataDefinition;
}

public sealed override bool Equals(object obj)
{
RuntimeSyntheticConstructorInfo other = obj as RuntimeSyntheticConstructorInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ namespace System.Reflection.Runtime.MethodInfos
//
// These methods implement the Get/Set methods on array types.
//
internal sealed partial class RuntimeSyntheticMethodInfo : RuntimeMethodInfo
internal sealed partial class RuntimeSyntheticMethodInfo : RuntimeMethodInfo, IRuntimeMemberInfoWithNoMetadataDefinition
{
private RuntimeSyntheticMethodInfo(SyntheticMethodId syntheticMethodId, String name, RuntimeTypeInfo declaringType, RuntimeTypeInfo[] parameterTypes, RuntimeTypeInfo returnType, InvokerOptions options, Func<Object, Object[], Object> invoker)
{
Debug.Assert(declaringType.IsArray);

_syntheticMethodId = syntheticMethodId;
_name = name;
_declaringType = declaringType;
Expand Down Expand Up @@ -54,6 +56,15 @@ public sealed override IEnumerable<CustomAttributeData> CustomAttributes
}
}

public sealed override bool HasSameMetadataDefinitionAs(MemberInfo other)
{
if (other == null)
throw new ArgumentNullException(nameof(other));

// This logic is written to match CoreCLR's behavior.
return other is MethodInfo && other is IRuntimeMemberInfoWithNoMetadataDefinition;
}

public sealed override bool Equals(Object obj)
{
RuntimeSyntheticMethodInfo other = obj as RuntimeSyntheticMethodInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,21 @@ public sealed override IEnumerable<CustomAttributeData> CustomAttributes
}
}

public sealed override bool HasSameMetadataDefinitionAs(MemberInfo other)
{
if (other == null)
throw new ArgumentNullException(nameof(other));

EcmaFormatRuntimePropertyInfo otherProperty = other as EcmaFormatRuntimePropertyInfo;
if (otherProperty == null)
return false;
if (!(_reader == otherProperty._reader))
return false;
if (!(_propertyHandle.Equals(otherProperty._propertyHandle)))
return false;
return true;
}

public sealed override bool Equals(Object obj)
{
EcmaFormatRuntimePropertyInfo other = obj as EcmaFormatRuntimePropertyInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,23 @@ public sealed override IEnumerable<CustomAttributeData> CustomAttributes
}
}

public sealed override bool HasSameMetadataDefinitionAs(MemberInfo other)
{
if (other == null)
throw new ArgumentNullException(nameof(other));

NativeFormatRuntimePropertyInfo otherProperty = other as NativeFormatRuntimePropertyInfo;
if (otherProperty == null)
return false;
if (!(_reader == otherProperty._reader))
return false;
if (!(_propertyHandle.Equals(otherProperty._propertyHandle)))
return false;
if (!(_definingTypeInfo.Equals(otherProperty._definingTypeInfo)))
return false;
return true;
}

public sealed override bool Equals(Object obj)
{
NativeFormatRuntimePropertyInfo other = obj as NativeFormatRuntimePropertyInfo;
Expand Down Expand Up @@ -126,6 +143,7 @@ public sealed override Object GetConstantValue()
return defaultValue;
}


public sealed override int MetadataToken
{
get
Expand Down
Loading