Open MichalPetryka opened 8 months ago
Tagging subscribers to this area: @dotnet/area-system-reflection See info in area-owners.md if you want to be subscribed.
Author: | MichalPetryka |
---|---|
Assignees: | - |
Labels: | `api-suggestion`, `area-System.Reflection` |
Milestone: | - |
Tagging subscribers to this area: @dotnet/area-system-runtime-compilerservices See info in area-owners.md if you want to be subscribed.
Author: | MichalPetryka |
---|---|
Assignees: | - |
Labels: | `api-suggestion`, `area-System.Runtime.CompilerServices`, `untriaged` |
Milestone: | - |
Background and motivation
IL has always exposed
ldtoken
instruction, but C# only exposed the type variant of it, making the method and field variants inaccessible. Requests for exposing those have been denied for either unclear semantics or the language team disliking the fact it'd promote reflection. With the handles being useful for some low level code and exposing things like function pointers, I'd say there's still value in adding a way for cheaply obtaining them with trimming and AOT friendly, fast and visiblity-ignoring way.UnsafeAccessor
s from #81741 meets all 3 criteria (unlike reflection or IL weaving without IgnoreAccessChecksTo).One question would be whether those should return
RuntimeXHandle
s orXInfo
s, since the API is low level and there are existing APIs to getXInfo
s from handles, I'd suggest it to be the former.Since IL exposes return type overloading on methods and fields (the latter is non CLS compliant though), the signature would need to indicate the type of those, for example with a dummy parameter at the end. The issue with this would be methods returning void.
If field
Offset
would be exposed onRuntimeFieldInfo
in #94976, this could supersede #93946.API Proposal
API Usage
Alternative Designs
Exposing
infoof/methodof/fieldof
andIgnoreAccessChecksTo
would be a possible alternative but both have already been rejected.Risks
Popularising reflection use.