Skip to content

Fix XML doc member ID lookup for generic type parameters#26

Merged
Malcolmnixon merged 2 commits into
mainfrom
fix/generic-type-xmldoc-id
Jun 17, 2026
Merged

Fix XML doc member ID lookup for generic type parameters#26
Malcolmnixon merged 2 commits into
mainfrom
fix/generic-type-xmldoc-id

Conversation

@Malcolmnixon

Copy link
Copy Markdown
Member

This pull request improves the handling of generic parameter types in XML documentation ID generation for .NET assemblies, ensuring accurate resolution and rendering of documentation for methods with generic parameters. The main change introduces a utility to correctly convert Mono.Cecil type names to the XML doc format, fixing issues where documentation was not found for such methods. Comprehensive regression and validation tests are also added to ensure correct behavior for both direct and inherited documentation, including cref-based inheritdoc scenarios.

Generic type name normalization and XML doc ID fixes:

  • Added ToXmlDocTypeName utility in DotNetEmitter to convert Mono.Cecil generic type names (e.g., `TypeNameThis pull request improves the handling of generic parameter types in XML documentation ID generation for .NET assemblies, ensuring accurate resolution and rendering of documentation for methods with generic parameters. The main change introduces a utility to correctly convert Mono.Cecil type names to the XML doc format, fixing issues where documentation was not found for such methods. Comprehensive regression and validation tests are also added to ensure correct behavior for both direct and inherited documentation, including cref-based inheritdoc scenarios.

Generic type name normalization and XML doc ID fixes:

1) to the XML doc ID format (e.g., TypeName{Arg}`), handling nested types and generic arguments. This ensures that generated XML doc IDs match those in the source documentation.

  • Updated all usages in DotNetEmitter and DotNetGenerator where parameter and return type names are used in XML doc ID generation to use ToXmlDocTypeName, fixing documentation lookup for methods with generic parameters. [1] [2] [3]

Testing and validation:

  • Added unit tests to validate ToXmlDocTypeName conversion logic, ensuring various generic and nested type cases are handled correctly.
  • Introduced comprehensive regression tests in DotNetGeneratorTests to verify that methods with generic parameter types correctly resolve and render their XML documentation, including:
    • Direct summaries for methods with generic parameters.
    • Inherited documentation via bare <inheritdoc />.
    • Inherited documentation via cref, both short alias and fully-qualified forms.
    • Scenarios with multiple generic parameters.

Test fixtures for generic parameter scenarios:

  • Added new fixture classes and interfaces (GenericParameterClass, IGenericParamInterface, GenericParamImplementation, CrefGenericDocClass) to cover a variety of generic parameter and inheritdoc scenarios in testing. [1] [2] [3] [4]

Malcolm Nixon and others added 2 commits June 17, 2026 16:48
Cecil's TypeReference.FullName encodes generic instantiations as
TypeName\N<Arg1,Arg2> but XML doc member IDs require TypeName{Arg1,Arg2}.
Methods whose parameter types include closed generic types (e.g.
IEnumerable<string>, IReadOnlyDictionary<string,object>, Action<T>) were
silently returning 'No description provided.' because the generated key
never matched the XML doc file entry.

Fix: add DotNetEmitter.ToXmlDocTypeName() that strips backtick-arity
markers and converts angle brackets to curly braces, then apply it in
both BuildMethodId (DotNetEmitter) and BuildMethodIdFromReference
(DotNetGenerator) for parameter and return types.

Tests added:
- 6 unit theory cases for ToXmlDocTypeName in DotNetEmitterTests
- Regression integration test in DotNetGeneratorTests using new
  GenericParameterClass fixture with IEnumerable<string>,
  IReadOnlyDictionary<string,object>, and Action<string> parameters

All 156 tests passing (net8/net9/net10).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Adds three fixtures and six integration tests covering the intersection
of inheritdoc resolution and generic-type XML doc ID encoding:

- IGenericParamInterface: interface with Process(IEnumerable<string>)
  and Transform(IReadOnlyDictionary<string,object>, Action<string>)
- GenericParamImplementation: bare <inheritdoc /> on both methods,
  exercising the chain-resolution path with generic parameter types
- CrefGenericDocClass: <inheritdoc cref='...' /> in both naming styles
  - Short C# alias form: IEnumerable{string}, Action{string}
  - Fully-qualified CLR form: System.Collections.Generic.IEnumerable{System.String}

Tests confirm:
- Bare inheritdoc resolves summary for single and multiple generic params
- Cref inheritdoc resolves summary using short alias form (compiler normalises)
- Cref inheritdoc resolves summary using fully-qualified CLR form
- None of the above render 'No description provided'

All 162 tests passing (net8/net9/net10).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 17, 2026 23:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request fixes XML doc member ID generation for methods whose signatures include generic instantiations by normalizing Mono.Cecil type names into the XML-doc encoding expected by compiled documentation, improving doc lookup/rendering in ApiMark.DotNet.

Changes:

  • Added DotNetEmitter.ToXmlDocTypeName to normalize Cecil generic type names (backtick arity + angle brackets) into XML doc ID form (curly braces) and normalize nested type separators.
  • Updated XML doc method-ID construction to use ToXmlDocTypeName for parameter and conversion-operator return types.
  • Added regression tests and new fixture types covering direct summaries and inherited documentation (<inheritdoc /> and <inheritdoc cref="..."/>) for generic-parameter signatures.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/ApiMark.DotNet/DotNetEmitter.cs Introduces ToXmlDocTypeName and applies it to method ID generation for parameters/return types.
src/ApiMark.DotNet/DotNetGenerator.cs Uses ToXmlDocTypeName when building method IDs from MethodReference (notably for inheritdoc/cref scenarios).
test/ApiMark.DotNet.Tests/DotNetEmitterTests.cs Adds unit tests validating Cecil-to-XML-doc type-name normalization.
test/ApiMark.DotNet.Tests/DotNetGeneratorTests.cs Adds end-to-end regression tests ensuring docs resolve for generic-parameter methods (direct and inherited/cref).
test/ApiMark.DotNet.Fixtures/IGenericParamInterface.cs New fixture interface with methods using generic-parameter types.
test/ApiMark.DotNet.Fixtures/GenericParamImplementation.cs New fixture implementation using bare <inheritdoc /> for generic-parameter methods.
test/ApiMark.DotNet.Fixtures/GenericParameterClass.cs New fixture class with generic-parameter method signatures and direct summaries.
test/ApiMark.DotNet.Fixtures/CrefGenericDocClass.cs New fixture class using cref-based inheritdoc for generic-parameter methods (short and fully-qualified forms).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Malcolmnixon Malcolmnixon merged commit 9097434 into main Jun 17, 2026
16 checks passed
@Malcolmnixon Malcolmnixon deleted the fix/generic-type-xmldoc-id branch June 17, 2026 23:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants