Skip to content

Extensions: ExtensionGroupingName and ExtensionMarkerName API proposal #80163

@jcouv

Description

@jcouv

Background and Motivation

The metadata design for extensions relies on nested types with content-based names. There's a grouping type name and a marker type name.
This proposal makes those names available via public APIs. Two usages have already been identified for those public APIs within rolsyn.

Relates to test plan #76130

Proposed API

namespace Microsoft.CodeAnalysis
{
    public interface ITypeSymbol : INamespaceOrTypeSymbol
    {
        [...]
        /// <summary>
        /// Is this a symbol for an extension declaration.
        /// </summary>
+       [MemberNotNullWhen(true, nameof(ExtensionGroupingName), nameof(ExtensionMarkerName))]
        bool IsExtension { get; }

+      /// <summary>
+      /// For extensions, returns the synthesized identifier for the grouping type.
+      /// Returns null otherwise.
+      /// </summary>
+      string? ExtensionGroupingName { get; }

+       /// <summary>
+       /// For extensions, returns the synthesized identifier for the marker type.
+       /// Returns null otherwise.
+       /// </summary>
+       string? ExtensionMarkerName { get; }
    }
}

Here are some eamples of returned values (it's a prefix followed by a hash):

            Assert.Equal("<G>$B8D310208B4544F25EEBACB9990FC73B", extension.ExtensionGroupingName);
            Assert.Equal("<M>$4F043C3369CC5922051EC35190062B5C", extension.ExtensionMarkerName);

Alternative Designs

The ExtensionMarkerName is already available via MetadataName API, but was added for consistency with ExtensionsGroupingName

Risks

N/A

Metadata

Metadata

Labels

Area-CompilersConcept-APIThis issue involves adding, removing, clarification, or modification of an API.Feature - Extension EverythingThe extension everything featureFeature Requestapi-approvedAPI was approved in API review, it can be implementedblockingAPI needs to reviewed with priority to unblock work

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions