-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add public API to retrieve metadata token from ISymbol #53486
Comments
Is zero every a valid value for a metadata token? |
Would it be better to add this to Location? Location already has IsInSource and IsInMetadata. And if it's from source, exposes the SyntaxTree/Span. For metadata it exposes the MetadataModule so it feels like a natural fit that it could also expose the MetadataToken. Then, you'd just get this from ISymbol.Locations in a consistent fashion. Thoughts? |
We could. However we currently reuse a single |
It's not. |
@AlekseyTs as API owner. |
@AlekseyTs Does the proposed design look good, or should we access the token thru Location API with the downside that we would allocate a lot of Location objects? |
@tmat, it looks like internally we don't have a token as an I agree that adding the information to |
Just my 50c. As a user of both Roslyn and SRM, I would be perfectly fine with having access to the strongly typed I am really looking forward to this! |
I wouldn't expose dependency on SRM in public API. The underlying token can be retrieved via Returning |
We already have such dependencies in our public API, such as around calling conventions and one older API that I can't remember off the top of my head. So I don't think there's any issue in another similar API. That said, if we think an int is better for other reasons, that's fine. |
@333fred Oh, interesting I did not know that. If that is so then returning |
I think we expose System.Reflection types from public APIs, but I am not sure if we actually expose any System.Reflection.Metadata types from public APIs today. Keeping that sounds compelling to me. |
https://sourceroslyn.io/#Microsoft.CodeAnalysis/Symbols/IMethodSymbol.cs,220 is from SRM. |
You are correct there is a precedent. However, that is an enum, effectively an int. Doesn't really say how we read metadata. |
API ReviewAPI Approved
|
Scenario
Implement improvements in Go To Definition when navigating to a metadata symbol (see #24349).
When the user invokes GTD on a metadata symbol we plan to identify the source file where the symbol is defined based on information stored in the PDB (combination of MethodDebugInformation, CustomDebugInformation and Document PDB tables).
Using debugger provided service we can first retrieve the PDB, find the source info in the PDB tables, then use Source Link (assuming it's present in the PDB), download the source file(s) that define the symbol from the source server, open these files in the editor and finally navigate to the requested symbol.
Problem
Currently
ISymbol
that represents a metadata symbol does not expose its metadata token. It is possible to find the token within the metadata usingMetadataReader
APIs but it would involve reimplementing the metadata signature decoder logic that's already implemented in the compiler. Instead we propose to expose the token fromISymbol
directly.Proposal
The API would return 0 in all cases when the symbol is not backed by a metadata entity (internally implemented as a PE symbol).
The text was updated successfully, but these errors were encountered: