Skip to content

Commit

Permalink
Adjust implementation of HasSameMetadataDefinitionAs to be resilient …
Browse files Browse the repository at this point in the history
…to failures of Expression.Compile.

[tfs-changeset: 1461633]
  • Loading branch information
dotnet-bot committed Apr 28, 2015
1 parent 7a6d256 commit 27367ab
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -305,13 +305,22 @@ public static bool HasSameMetadataDefinitionAs(this MemberInfo mi1, MemberInfo m
else
{
var parameter = Expression.Parameter(memberInfo);
s_GetMetadataToken = Expression.Lambda<Func<MemberInfo, int>>(Expression.Property(parameter, property), new[] { parameter }).Compile();
try
{
s_GetMetadataToken = Expression.Lambda<Func<MemberInfo, int>>(Expression.Property(parameter, property), new[] { parameter }).Compile();
}
catch
{
// Platform might not allow access to the property
s_GetMetadataToken = null;
}
}
}

if ((object)s_GetMetadataToken != null)
var getMetadataToken = s_GetMetadataToken;
if ((object)getMetadataToken != null)
{
return s_GetMetadataToken(mi1) == s_GetMetadataToken(mi2);
return getMetadataToken(mi1) == getMetadataToken(mi2);
}

return mi1.IsEquivalentTo(mi2);
Expand Down

0 comments on commit 27367ab

Please sign in to comment.