Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Step 1 of fix for disabled System.Dynamic.Runtime test on ILC #20991

Merged
merged 2 commits into from Jun 14, 2017
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 @@ -240,8 +240,32 @@ private static bool IsTypeParameterEquivalentToTypeInst(this Type typeParam, Typ
{
try
{
// See if MetadataToken property is available.
Type memberInfo = typeof(MemberInfo);

// First, try the actual API. (Post .NetCore 2.0) The api is the only one that gets it completely right on frameworks without MetadataToken.
MethodInfo apiMethod = memberInfo.GetMethod(
"HasSameMetadataDefinitionAs",
BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.ExactBinding,
binder: null,
types: new Type[] { typeof(MemberInfo) },
modifiers: null);
if (apiMethod != null)
{
Func<MemberInfo, MemberInfo, bool> apiDelegate = (Func<MemberInfo, MemberInfo, bool>)(apiMethod.CreateDelegate(typeof(Func<MemberInfo, MemberInfo, bool>)));
try
{
bool result = apiDelegate(m1, m2);
// it worked, so publish it
s_MemberEquivalence = apiDelegate;
return result;
}
catch
{
// Api found but apparently stubbed as not supported. Continue on to the next fallback...
}
}

// See if MetadataToken property is available.
PropertyInfo property = memberInfo.GetProperty("MetadataToken", typeof(int), Array.Empty<Type>());

if ((object)property != null && property.CanRead)
Expand Down
7 changes: 6 additions & 1 deletion src/Microsoft.CSharp/src/Resources/Microsoft.CSharp.rd.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@
</Type>
<Type Name="Object" Dynamic="Required Public" />
</Namespace>
<Namespace Name="System.Reflection">
<Type Name="MemberInfo">
<Method Name="HasSameMetadataDefinitionAs" Dynamic="Required"/>
</Type>
</Namespace>
</Assembly>

<Assembly Name="System.Linq.Expressions">
Expand All @@ -95,4 +100,4 @@
<Type Name="System.Reflection.Missing" Dynamic="Required All" />
</Assembly>
</Library>
</Directives>
</Directives>