CommentsExtractor 26.1.63689
dotnet add package CommentsExtractor --version 26.1.63689
NuGet\Install-Package CommentsExtractor -Version 26.1.63689
<PackageReference Include="CommentsExtractor" Version="26.1.63689" />
<PackageVersion Include="CommentsExtractor" Version="26.1.63689" />
<PackageReference Include="CommentsExtractor" />
paket add CommentsExtractor --version 26.1.63689
#r "nuget: CommentsExtractor, 26.1.63689"
#:package CommentsExtractor@26.1.63689
#addin nuget:?package=CommentsExtractor&version=26.1.63689
#tool nuget:?package=CommentsExtractor&version=26.1.63689
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.GetCommentsmethod 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
Reference the Attributes and Generator: In your project file (
.csproj), add the following:<ItemGroup> <PackageReference Include="CommentExtractor" Version="*" OutputItemType="Analyzer" ReferenceOutputAssembly="false" /> </ItemGroup>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:
- Extracts the XML documentation string using Roslyn's
GetDocumentationCommentXml(). - Generates a private constant string containing the XML.
- 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.
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- CommentsExtractor.Generator (>= 26.1.63689)
- CommentsExtractor.RuntimeDependencies (>= 26.1.63689)
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 |