This repository was archived by the owner on Nov 1, 2020. It is now read-only.
Implement HasSameMetadataDefinitionAs() on CoreRT#3675
Merged
1 commit merged intonmirrorfrom May 22, 2017
unknown repository
Merged
Implement HasSameMetadataDefinitionAs() on CoreRT#36751 commit merged intonmirrorfrom unknown repository
1 commit merged intonmirrorfrom
unknown repository
Conversation
This api was approved here: https://github.com/dotnet/corefx/issues/5884 and is a necessary step to fixing the System.Dynamic.Runtime.Tests failure: https://github.com/dotnet/corefx/issues/19895 which is caused by Microsoft.CSharp trying to do the impossible and emulate this api without GetMetadataToken() support. This emulates the behavior of the CoreCLR version (which simply compares MetadataTokens and Modules.) The CoreCLR version of this is currently a PR dotnet/coreclr#11774 -- Copied from CoreCLR commit text--- This results in the following behavior for these corner cases. With the possible exception of #3, I think they are tolerable enough to accept and codify: 1. "other" implemented by an entirely different Reflection provider than "this". Behavior: returns false without invoking any methods on the "other" Member. To change it to throw an ArgumentException would mean extra cast checks against the 6 possible Runtime types (or having said RuntimeTypes implement a sentinel interface.) Given that HasSameMetadataDefinitionAs() is a "looser cousin of Equals()" and "Equals()" doesn't throw for objects from a different universe, this seems reasonable. 2. Arrays, ByRefs, Pointers and Types from GetTypeFromCLSID() Behavior: Arrays, ByRefs, Pointers all return token 0x0600000 and so they'll return "true" wrt to each other (provided both types are implemented by the same provider.) CLSID types all return the typedef of __ComObject so they'll return "true" wrt to each other. The constructor exposed by CLSID types all return the typedef of some constructor on __ComObject so they'll return "true" wrt to each other. I do not think these are interesting cases that merit special handling. These types will never appear in an enumeration of the members of a type. (The fact that Reflection surfaces them in objects that are assignable to MemberInfo is a structural flaw in Reflection's object model.) 3. Synthesized constructors and methods on array types. Behavior: These methods all return 0x06000000 as a token so the constructors will all compare true wrt each other, and likewise with the methods. This is a bit crummy though it's not clear what the "right" policy should look like. I could be persuaded to throw NotSupported for these, to leave the possibility open for a better story later. On the other hand, I wouldn't demand it either.
This pull request was closed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This api was approved here:
https://github.com/dotnet/corefx/issues/5884
and is a necessary step to fixing the System.Dynamic.Runtime.Tests
failure:
https://github.com/dotnet/corefx/issues/19895
which is caused by Microsoft.CSharp trying to do the impossible
and emulate this api without GetMetadataToken() support.
This emulates the behavior of the CoreCLR version
(which simply compares MetadataTokens and Modules.)
The CoreCLR version of this is currently a PR
dotnet/coreclr#11774
-- Copied from CoreCLR commit text---
This results in the following behavior for these
corner cases. With the possible exception of #3,
I think they are tolerable enough to accept and codify:
"other" implemented by an entirely different Reflection
provider than "this".
Behavior:
returns false without invoking any methods on the
"other" Member.
To change it to throw an ArgumentException would
mean extra cast checks against the 6 possible
Runtime types (or having said RuntimeTypes implement
a sentinel interface.)
Given that HasSameMetadataDefinitionAs() is a
"looser cousin of Equals()" and "Equals()"
doesn't throw for objects from a different universe,
this seems reasonable.
Arrays, ByRefs, Pointers and Types from GetTypeFromCLSID()
Behavior:
Arrays, ByRefs, Pointers all return token 0x0600000
and so they'll return "true" wrt to each other (provided
both types are implemented by the same provider.)
CLSID types all return the typedef of __ComObject
so they'll return "true" wrt to each other.
The constructor exposed by CLSID types all return
the typedef of some constructor on __ComObject so
they'll return "true" wrt to each other.
I do not think these are interesting cases that merit
special handling. These types will never appear
in an enumeration of the members of a type. (The
fact that Reflection surfaces them in objects
that are assignable to MemberInfo is a structural
flaw in Reflection's object model.)
Synthesized constructors and methods on array types.
Behavior:
These methods all return 0x06000000 as a token
so the constructors will all compare true wrt
each other, and likewise with the methods.
This is a bit crummy though it's not clear
what the "right" policy should look like.
I could be persuaded to throw NotSupported
for these, to leave the possibility open
for a better story later. On the other hand,
I wouldn't demand it either.