Skip to content

Feature request: C# generator should format generated methods as XML doc cref elements #11202

Description

@ArcturusZhang

Feature request

Please add support for formatting generated C# method references as XML documentation cref elements.

Scenario

The Azure SDK management generator needs to emit documentation that points from an extension method to the mockable method users should mock instead:

<description>To mock this method, please mock <see cref="MockableType.Method(Type1, Type2)"/> instead.</description>

For methods with generic parameter types, the cref must use XML-doc generic syntax, for example:

<see cref="MockableAzureGeneratorMgmtTypeSpecTestsSubscriptionResource.GetBazsAsync(int?, IEnumerable{string}, CancellationToken)"/>

Current behavior

I validated the existing C# generator :C formatter in two ways:

  1. Formatting individual CSharpType values with :C and composing them inside cref="..." does not work because :C emits complete XML doc tags/prose, such as <see cref="Type"/> or <see cref="IEnumerable{T}"/> where <c>T</c> is of type <see cref="string"/>.
  2. Formatting MethodSignature directly with :C, for example $"To mock this method, please mock {targetSignature:C} instead.", compiles but emits <see cref="Generator.Primitives.MethodSignature"/>, referencing the MethodSignature type rather than the represented generated method.

CSharpType also does not appear to expose an XML-doc cref string conversion API. ToString() emits C# syntax such as global::System.Collections.Generic.IEnumerable<string>, not XML-doc cref syntax such as IEnumerable{string}.

Requested API/behavior

Please consider supporting :C on a generated C# method representation, such as MethodSignature or MethodProvider, to emit a complete cref element for the represented generated method, including the declaring type and parameter type list.

If the declaring type cannot be inferred from MethodSignature, a helper/API that accepts the declaring CSharpType plus the method signature would also work.

This would let generators rely on base C# generator XML-doc formatting instead of manually building cref strings and generic type parameter syntax.

Context: Azure SDK issue Azure/azure-sdk-for-net#60758

Metadata

Metadata

Assignees

No one assigned

    Labels

    emitter:client:csharpIssue for the C# client emitter: @typespec/http-client-csharpfeatureNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions