-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
[API Proposal]: Simplify lookup of parsed TypeName in metadata #101774
Comments
I have filled this proposal based on my experience with implementing lookup of parsed TypeName in tools #101767. @adamsitnik Any thoughts about this API? |
ECMA-335 6th edition §II.22.14 says
The proposed GetMetadataNamespaceAndName() API looks like it could easily mislead callers into not recognizing types whose names have been split at a “.” other than the last one. |
Good point. .NET Framework and .NET Core never followed this rule in practice. The full type name is expected to be split in namespace + name using this algorithm. We may want to add a note to https://github.com/dotnet/runtime/blob/main/docs/design/specs/Ecma-335-Augments.md . |
Does it always return
This particular library can be consumed by Full Framework apps and they often struggle to use
I see why low level metadata parsers need that, but I find it too specific to particular use case. What would we benefit from exposing such public API? |
For non-nested types, it returns unescaped FullName split into name and namespace.
I do not mind changing this to whatever else API review prefers; or expose the static helper methods instead.
System.Reflection.Metadata is a library for low-level metadata readers. Every tool or library that reads metadata in its entirety using this library needs this functionality. Every shipping Also, I was looking at converting Lines 293 to 330 in 71abc26
|
You have convinced me 👍 FWIW the alternative design for me: namespace System.Reflection.Metadata;
public class TypeName
{
public string Name { get; }
public string FullName { get; }
+ public string Namespace { get; }
+ public static string Unescape(string name);
} |
Update the proposal at the top. I think it is a better starting point for the API review discussion. |
Moving to v10 since we have reached the "feature complete" milestone; this is still on the API review backlog. |
namespace System.Reflection.Metadata;
public partial class TypeName
{
public string Namespace { get; }
public static string Unescape(string name);
} |
Background and motivation
The recently introduced System.Reflection.Metadata.TypeName is likely to be frequently combined with lookup of the type in metadata. The information required to lookup a type in ECMA335 metadata tables is unescaped (namespace, name) tuple. This information is not provided by the
TypeName
type today. In order to lookup the parser type name in metadata, the consumers have to implement unescaping and full type name splitting helper methods to convert the information providedTypeName
this tuple.API Proposal
API Usage
Alternative Designs
Alt option 1: Introduce a method that returns an unescaped (namespace, name) tuple.
Alt option 2: Change the Namespace and Name methods to return unescaped names (different from reflection). It would avoid need to introduce Unescape method.
Risks
No response
The text was updated successfully, but these errors were encountered: