Open tmat opened 6 months ago
MetadataDisplayFormat
, can we just expose UsePlusForNestedTypes
option?Conclusion: Needs work. Exposing a UsePlusForNestedTypes
option seems reasonable by itself. A format would then need to be very precise as to what it supports and where.
My bad, I didn't notice that s_metadataDisplayFormat
is only used by tests and is not the full implementation of fully qualified name.
The intention was to allow the code written in the usage example - that is, given a ITypeSymbol
return a fully qualified metadata name in the format that System.Reflection parses to load a type. See https://github.com/dotnet/runtime/blob/main/src/libraries/Common/src/System/Reflection/TypeNameParser.cs.
This format is also used in ECMA-335 when serializing the value of System.Type for custom attribute blob. This is implemented by the compiler here: https://github.com/dotnet/roslyn/blob/main/src/Compilers/Core/Portable/PEWriter/TypeNameSerializer.cs
Examples:
typeof(X<int*[]>.Y<string>[,,]))
X`1+Y`1[[System.Int32*[], System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.String, System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]][,,]
typeof(X<>.Y<>)
X`1+Y`1
Background and Motivation
After a compilation is emitted and the resulting image is loaded, we need to find a type in the loaded
Assembly
that corresponds to a sourceINamedTypeSymbol
defined in the compilation.Proposed API
Implemented like so: https://github.com/dotnet/roslyn/blob/cf8b467a73d6f7d5ad96b12d1ba457bdc7109992/src/Compilers/Core/Portable/SourceGeneration/Nodes/SyntaxValueProvider_ForAttributeWithMetadataName.cs#L60-L61
Usage Examples
Alternative Designs
Risks