RhoMicro.CodeAnalysis.UtilityGenerators
21.0.6
Prefix Reserved
See the version list below for details.
dotnet add package RhoMicro.CodeAnalysis.UtilityGenerators --version 21.0.6
NuGet\Install-Package RhoMicro.CodeAnalysis.UtilityGenerators -Version 21.0.6
<PackageReference Include="RhoMicro.CodeAnalysis.UtilityGenerators" Version="21.0.6"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="RhoMicro.CodeAnalysis.UtilityGenerators" Version="21.0.6" />
<PackageReference Include="RhoMicro.CodeAnalysis.UtilityGenerators"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add RhoMicro.CodeAnalysis.UtilityGenerators --version 21.0.6
#r "nuget: RhoMicro.CodeAnalysis.UtilityGenerators, 21.0.6"
#:package RhoMicro.CodeAnalysis.UtilityGenerators@21.0.6
#addin nuget:?package=RhoMicro.CodeAnalysis.UtilityGenerators&version=21.0.6
#tool nuget:?package=RhoMicro.CodeAnalysis.UtilityGenerators&version=21.0.6
What is this?
This project contains generators and analyzers that help writing generators and analyzers:
Installation
<PackageReference Include="RhoMicro.CodeAnalysis.UtilityGenerators" Version="*">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Attribute Factory
TODO
File Inclusion
Annotate with the IncludeFileAttribute any type or assembly in order to generate code
that includes the file containing the target in a generator context via
RegisterPostInitializationOutput.
Example:
namespace MyNamespace;
using System;
using RhoMicro.CodeAnalysis;
[IncludeFile]
internal class Foo
{
public static Int32 Bar() => 42;
}
Foo.cs
// <auto-generated>
// This file was generated by the RhoMicro.CodeAnalysis.FileInclusionGenerator.
// </auto-generated>
using Microsoft.CodeAnalysis;
using System;
namespace RhoMicro.CodeAnalysis.Generated
{
internal static class IncludedFileSources
{
public static void RegisterToContext(IncrementalGeneratorInitializationContext context)
{
context.RegisterPostInitializationOutput(c =>
{c.AddSource(
"RhoMicro_CodeAnalysis_Foo.g.cs",
$$"""
// <auto-generated>
// This file was generated by RhoMicro.CodeAnalysis.FileInclusionGenerator.
// </auto-generated>
#pragma warning disable
namespace RhoMicro.CodeAnalysis;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
[IncludeFile]
internal class Foo
{
public static Int32 Bar() => 42;
}
""");
}); }
}
}
IncludedFiles.g.cs
NonEquatable
Annotate types with the NonEquatableAttribute to generate throwing implementations for Equals
and GetHashCode. This generator helps detect illegal objects in incremental generator pipelines.
Example:
namespace MyNamespace;
using System;
using RhoMicro.CodeAnalysis;
[NonEquatable]
internal partial class Foo
{
public static Int32 Bar() => 42;
}
Foo.cs
// <auto-generated>
// This file was generated by RhoMicro.CodeAnalysis.NonEquatableGenerator
// The tool used to generate this code may be subject to license terms;
// this generated code is however not subject to those terms, instead it is
// subject to the license (if any) applied to the containing project.
// </auto-generated>
#pragma warning disable
#nullable enable
namespace MyNamespace;
partial class Foo
{
/// <inheritdoc/>
public sealed override bool Equals(object obj) => throw new global::System.NotSupportedException("global::MyNamespace.Foo.Equals(object) is not supported.");
/// <inheritdoc/>
public bool Equals(global::MyNamespace.Foo obj) => throw new global::System.NotSupportedException("global::MyNamespace.Foo.Equals(global::MyNamespace.Foo) is not supported.");
/// <inheritdoc/>
public sealed override int GetHashCode() => throw new global::System.NotSupportedException("global::MyNamespace.Foo.GetHashCode() is not supported.");
}
MyNamespace_Foo.g.cs
Type Symbol Pattern
Annotate static partial methods with the TypeSymbolPattern attribute to generate an implementation
matching a pattern of the attributes type parameter against the method symbol paremeter.
Example:
namespace MyNamespace;
using System;
using Microsoft.CodeAnalysis;
using RhoMicro.CodeAnalysis;
internal static partial class Foo
{
[TypeSymbolPattern(typeof(List<String>))]
public static partial Boolean IsStream(ITypeSymbol symbol);
}
Foo.cs
// <auto-generated>
// This file was generated by RhoMicro.CodeAnalysis.TypeSymbolPatternGenerator
// The tool used to generate this code may be subject to license terms;
// this generated code is however not subject to those terms, instead it is
// subject to the license (if any) applied to the containing project.
// </auto-generated>
#pragma warning disable
#nullable enable
namespace MyNamespace;
partial class Foo
{
public static partial bool IsStringList(global::Microsoft.CodeAnalysis.ITypeSymbol? type)
{
var result = type is global::Microsoft.CodeAnalysis.INamedTypeSymbol
{
Name: "List",
TypeArguments:[global::Microsoft.CodeAnalysis.INamedTypeSymbol
{
Name: "String",
TypeArguments:[],
ContainingNamespace:
{
Name: "System",
ContainingNamespace:
{
IsGlobalNamespace: true
}
}
}
],
ContainingNamespace:
{
Name: "Generic",
ContainingNamespace:
{
Name: "Collections",
ContainingNamespace:
{
Name: "System",
ContainingNamespace:
{
IsGlobalNamespace: true
}
}
}
}
}
;
return result;
}
public static bool IsStringList(global::Microsoft.CodeAnalysis.ITypeSymbol? type, [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out global::Microsoft.CodeAnalysis.INamedTypeSymbol? outType)
{
var result = IsStringList(type);
outType = result ? (global::Microsoft.CodeAnalysis.INamedTypeSymbol) type : null;
return result;
}
}
MyNamespace_Foo.g.cs_
Note that containing types are not currently supported.
Templating
A string templating engine is provided via the Template attribute.
The templating syntax uses the following delimiters:
- Code blocks:
- enclosed in
{:and:} - for C# code
- enclosed in
- Render blocks:
- enclosed in
(:and:) - for embedding (rendering) expressions or instantiating child templates.
- enclosed in
- Template blocks:
- enclosed in
<:and:> - to pass child content to child templates.
- enclosed in
Examples
Simple Text-Only template
namespace MyNamespace;
using RhoMicro.CodeAnalysis;
[Template(
"""
Hello, world!
Welcome to our templating engine demo.
""")]
internal partial class Foo;
Foo.cs
// <auto-generated>
// This file was generated by RhoMicro.CodeAnalysis.TemplatingGenerator
// The tool used to generate this code may be subject to license terms;
// this generated code is however not subject to those terms, instead it is
// subject to the license (if any) applied to the containing project.
// </auto-generated>
#pragma warning disable
#nullable enable
using static global::RhoMicro.CodeAnalysis.Library.Text.Templating.Indentations;
namespace MyNamespace;
partial class Foo :
global::RhoMicro.CodeAnalysis.Library.Text.Templating.ITemplate
{
public override string ToString() => global::RhoMicro.CodeAnalysis.Library.Text.Templating.TemplateRenderer.Render(this);
public string ToString(global::System.Threading.CancellationToken cancellationToken) => global::RhoMicro.CodeAnalysis.Library.Text.Templating.TemplateRenderer.Render(this, cancellationToken);
public void Render<__TBody>(ref global::RhoMicro.CodeAnalysis.Library.Text.Templating.TemplateRenderer __renderer, __TBody __body)
where __TBody : global::RhoMicro.CodeAnalysis.Library.Text.Templating.ITemplate
{
__renderer.ThrowIfCancellationRequested();
// This template was taken from: F:\dev\git\RhoMicro.CodeAnalysis\UtilityGenerators.Tests.E2E\Templating\Foo.cs(6,0)
const string __template =
"""
Hello, world!
Welcome to our templating engine demo.
""";
__renderer.Render(__template.AsSpan(0, 52));
}
}
MyNamespace_Foo.g.cs
Building The Project
This project is running the generators contained against itself. To do this, run the bootstrap.ps1 script.
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- Microsoft.CodeAnalysis.CSharp (>= 4.12.0)
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 |
|---|---|---|
| 22.0.3 | 241 | 8/20/2025 |
| 22.0.2 | 171 | 8/20/2025 |
| 22.0.1 | 175 | 7/12/2025 |
| 21.1.2 | 196 | 6/25/2025 |
| 21.1.0 | 191 | 6/25/2025 |
| 21.0.6 | 182 | 6/24/2025 |
| 20.1.5 | 419 | 5/22/2025 |
| 20.1.4 | 155 | 5/17/2025 |
| 20.1.2 | 177 | 5/11/2025 |
| 20.0.0 | 608 | 3/26/2025 |
| 19.5.0 | 529 | 3/25/2025 |
| 19.4.0 | 188 | 3/17/2025 |
| 19.3.0 | 186 | 3/17/2025 |
| 19.2.0 | 180 | 3/17/2025 |
| 19.1.0 | 214 | 3/9/2025 |
| 19.0.2 | 208 | 3/9/2025 |
| 19.0.1 | 169 | 3/8/2025 |
| 19.0.0 | 205 | 3/8/2025 |
| 18.0.3 | 136 | 3/2/2025 |
| 18.0.2 | 141 | 3/2/2025 |
| 18.0.1 | 144 | 3/2/2025 |
| 17.1.3 | 138 | 1/24/2025 |
| 17.1.2 | 151 | 12/30/2024 |
| 17.1.1 | 140 | 12/30/2024 |
| 17.1.0 | 134 | 12/30/2024 |
| 17.0.2 | 132 | 12/24/2024 |
| 16.1.2 | 144 | 12/22/2024 |
| 16.1.1 | 145 | 12/21/2024 |
| 16.1.0 | 139 | 12/20/2024 |
| 16.0.4 | 158 | 12/18/2024 |
| 16.0.3 | 142 | 12/18/2024 |
| 16.0.0 | 170 | 12/18/2024 |
| 15.3.4 | 472 | 12/7/2024 |
| 15.3.3 | 148 | 12/7/2024 |
| 15.3.2 | 155 | 12/7/2024 |
| 15.3.1 | 152 | 12/7/2024 |
| 15.3.0 | 163 | 12/6/2024 |
| 15.2.4 | 169 | 12/6/2024 |
| 15.2.3 | 169 | 12/6/2024 |
| 15.1.7 | 287 | 7/15/2024 |
| 15.1.6 | 219 | 6/11/2024 |
| 15.1.5 | 234 | 3/26/2024 |
| 15.1.4 | 176 | 3/26/2024 |
| 15.1.3 | 262 | 3/11/2024 |
| 15.1.2 | 194 | 3/8/2024 |
| 15.1.1 | 223 | 3/4/2024 |
| 15.1.0 | 202 | 2/28/2024 |
| 15.0.1 | 176 | 2/22/2024 |
| 15.0.0 | 224 | 2/20/2024 |
| 14.0.5 | 203 | 2/19/2024 |
| 14.0.4 | 143 | 2/19/2024 |
| 14.0.3 | 158 | 2/19/2024 |
| 14.0.2 | 186 | 2/15/2024 |
| 14.0.0 | 181 | 2/15/2024 |
| 14.0.0-alpha.30 | 93 | 2/15/2024 |
| 14.0.0-alpha.29 | 83 | 2/15/2024 |
| 14.0.0-alpha.28 | 89 | 2/15/2024 |
| 14.0.0-alpha.27 | 95 | 2/15/2024 |
| 14.0.0-alpha.26 | 96 | 2/15/2024 |
| 14.0.0-alpha.25 | 97 | 2/15/2024 |
| 14.0.0-alpha.24 | 96 | 2/15/2024 |
| 14.0.0-alpha.22 | 88 | 2/15/2024 |
| 14.0.0-alpha.20 | 101 | 2/15/2024 |
| 13.0.0 | 281 | 1/8/2024 |
| 12.1.2 | 210 | 1/6/2024 |
| 12.1.1 | 191 | 1/6/2024 |
| 12.1.0 | 181 | 1/6/2024 |
| 12.0.9 | 224 | 1/5/2024 |
| 12.0.8 | 211 | 1/5/2024 |
| 11.0.0 | 215 | 12/16/2023 |
| 8.0.3 | 187 | 12/11/2023 |
| 8.0.2 | 204 | 12/11/2023 |
| 8.0.0 | 231 | 12/11/2023 |