CommentsExtractor 26.1.63689

dotnet add package CommentsExtractor --version 26.1.63689
                    
NuGet\Install-Package CommentsExtractor -Version 26.1.63689
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CommentsExtractor" Version="26.1.63689" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CommentsExtractor" Version="26.1.63689" />
                    
Directory.Packages.props
<PackageReference Include="CommentsExtractor" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add CommentsExtractor --version 26.1.63689
                    
#r "nuget: CommentsExtractor, 26.1.63689"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package CommentsExtractor@26.1.63689
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=CommentsExtractor&version=26.1.63689
                    
Install as a Cake Addin
#tool nuget:?package=CommentsExtractor&version=26.1.63689
                    
Install as a Cake Tool

CommentExtractor Source Generator

A Roslyn-based source code generator for C# (.NET 10) that extracts XML documentation comments from public methods and properties at compile time and makes them available at runtime.

Features

  • Automatic Extraction: Automatically finds all classes annotated with [ExtractComments].
  • Public Member Support: Extracts triple-slash (///) XML documentation for all public methods and properties.
  • Overload Support: Correctly handles method overloads, allowing you to retrieve all matching comments by member name.
  • Unique Identification: Generates unique constant names for each member, including parameter types for methods to ensure no collisions.
  • Efficient Retrieval: Provides a static CommentRegistry.GetComments method lookup.

Project Structure

  • CommentExtractor.Attributes: Contains the [ExtractComments] attribute.
  • CommentExtractor.Generator: The Roslyn Incremental Source Generator.
  • CommentExtractor.Tests: A sample project demonstrating usage and verification.

Setup

  1. Reference the Attributes and Generator: In your project file (.csproj), add the following:

    <ItemGroup>
      <PackageReference Include="CommentExtractor" Version="*"
                        OutputItemType="Analyzer" 
                        ReferenceOutputAssembly="false" />
    </ItemGroup>
    
  2. Enable XML Documentation: The generator relies on the compiler's XML documentation extraction. You must enable it in your .csproj:

    <PropertyGroup>
      <GenerateDocumentationFile>true</GenerateDocumentationFile>
    
      <NoWarn>$(NoWarn);CS1591</NoWarn>
    </PropertyGroup>
    

Usage

1. Annotate your class

using CommentExtractor.Attributes;

namespace MyNamespace;

[ExtractComments]
public class MyService
{
    /// <summary>
    /// This is a sample method.
    /// </summary>
    /// <param name="id">The identifier.</param>
    public void DoWork(int id) { }

    /// <summary>
    /// Gets or sets the name.
    /// </summary>
    public string Name { get; set; }
}

2. Retrieve comments at runtime

Use the CommentRegistry class (located in the CommentExtractor.Attributes namespace):

using CommentExtractor.Attributes;

string[] comments = CommentRegistry.GetComments("MyNamespace.MyService", "DoWork");

foreach (var comment in comments)
{
    Console.WriteLine(comment);
}

How it works

The generator scans for classes marked with [ExtractComments]. For each such class, it iterates through all public methods and properties. It then:

  1. Extracts the XML documentation string using Roslyn's GetDocumentationCommentXml().
  2. Generates a private constant string containing the XML.
  3. Populates a static dictionary mapping (FullTypeName, MemberName) to an array of these constants.

This allows for extremely fast retrieval of documentation at runtime without using heavy Reflection or parsing XML files manually.

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
26.1.63689 231 1/23/2026
26.1.63688 222 1/23/2026
26.1.63642 234 1/21/2026
26.1.63641 224 1/21/2026
26.1.63640 231 1/21/2026
26.1.63639 229 1/21/2026
26.1.63638 231 1/21/2026
26.1.63637 106 1/21/2026
26.1.63636 111 1/21/2026
26.1.63635 115 1/21/2026
26.1.63634 106 1/21/2026
26.1.63633 112 1/21/2026
26.1.63631 116 1/21/2026
26.1.63629 107 1/21/2026
26.1.63628 104 1/21/2026
26.1.63625 111 1/21/2026
26.1.63624 106 1/21/2026