Skip to content

Commit

Permalink
Step 1 of fix for disabled System.Dynamic.Runtime test on ILC (dotnet…
Browse files Browse the repository at this point in the history
…#20991)

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

(https://github.com/dotnet/corefx/issues/19895)

Make Microsoft.CSharp use the the real HasMetadataDefinitionAs()
api if it exists on the running framework. Since this library
is built on netstandard, it still needs to fall back on its
emulation on older frameworks.

Actual removal of the ActiveIssue will have to wait until
the new System.Runtime reference assembly propagates to
the Project N tree and the new api becomes reflectable.

* Merge the lightup checks.
  • Loading branch information
atsushikan authored and VSadov committed Jun 14, 2017
1 parent 99dc6c9 commit 4b830e6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
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>

0 comments on commit 4b830e6

Please sign in to comment.