RhoMicro.CodeAnalysis.UtilityGenerators
17.1.1
See the version list below for details.
dotnet add package RhoMicro.CodeAnalysis.UtilityGenerators --version 17.1.1
NuGet\Install-Package RhoMicro.CodeAnalysis.UtilityGenerators -Version 17.1.1
<PackageReference Include="RhoMicro.CodeAnalysis.UtilityGenerators" Version="17.1.1"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add RhoMicro.CodeAnalysis.UtilityGenerators --version 17.1.1
#r "nuget: RhoMicro.CodeAnalysis.UtilityGenerators, 17.1.1"
// Install RhoMicro.CodeAnalysis.UtilityGenerators as a Cake Addin #addin nuget:?package=RhoMicro.CodeAnalysis.UtilityGenerators&version=17.1.1 // Install RhoMicro.CodeAnalysis.UtilityGenerators as a Cake Tool #tool nuget:?package=RhoMicro.CodeAnalysis.UtilityGenerators&version=17.1.1
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>
Templating
A string templating engine is provided via the TemplatingGenerator
.
Templating is done via attributes on template types. A generator analyzes these and generates an implementation for rendering the template, similar to the ASP.Net razor engine.
Notes:
- holes:
- Value (singleline, multiple):
�(foo)
forbuilder.Append(foo);
- builtin conversions to
ReadOnlySpan<Char>
for common types ⇒TemplateHelpers.GetCharSpan(foo)
- detect template type and use
builder.Render
instead- Code (multiline, multiple):
�{foreach(var bar in foo){�(bar)}}
forforeach(var bar in foo){builder.Append(bar);}
- → unlike razor, we require explicit hole type when used in code blocks
- escape with
\
- generated templates must always be generated using escaped source newlines, so we may efficiently use spans on a oneliner template constant
Sample Usage
namespace RhoMicro.CodeAnalysis.Foo;
[Template(
"""
// \�(escaped hole)
// \\�(Name) (unescaped hole)
public �(Accessibility) class �(Name)
{�{
foreach(var member in Members)
{
$(member)
}
}}
""")]
internal sealed partial class FooTemplate
{
public FooTemplate(String accessibility, String name)
{
Accessibility = accessibility;
Name = name;
}
public String Accessibility { get; }
public String Name { get; }
public List<MemberTemplate> Members { get; } = [];
}
should generate something like:
namespace RhoMicro.CodeAnalysis.Foo;
partial class FooTemplate : global::RhoMicro.CodeAnalysis.Library.Text.Templating.Template
{
public override void Render(global::RhoMicro.CodeAnalysis.Library.Text.Templating.BufferedStringBuilder builder)
{
// this should be a one-liner with source newlines
const string __template =
"""
// \�(escaped hole)
// \\�(Name) (unescaped hole)
public �(Accessibility) class �(Name)
{�{
foreach(var member in Members)
{
$(member)
}
}}
""";
builder.Append(__template.AsSpan()[..57]);
builder.Append(TemplateUtilities.GetCharSpan(Accessibility));
// append span of text part
builder.Append(TemplateUtilities.GetCharSpan(Name));
// append span of new line, open brace after Name
// insert newline, tab before each following line in code block
foreach(var member in Members)
{
$(member)
}
// omit trailing whitespace in codeblock up to closing brace
// append closing brace from template
}
}
Grammar
Non-Terminals
Template
template = *(text / hole)
Text
text = *(%x00-%x5B %x5D-%xA6 / %xA8-%xFF / escaped)
Escaped
escaped = ESC (MRK / ESC)
Hole
hole = value-hole / code-hole
Value Hole
value-hole = MRK OPA identifier CPA
Code Hole
code-hole = MRK OBR *(text / value-hole) CBR
Identifier
identifier = ALPHA *(ALPHA / DIGIT / "_")
Terminals
Escape
ESC = %x5C
%5C
=\
Marker
MRK = %xA7
%A7
=�
Opening Curly Brace
OBR = %x7B
%7B
={
Closing Curly Brace
CBR = %x7D
%7D
=}
Opening Parenthesis
OPA = %x28
%28
=(
Closing Parenthesis
CPA = %x29
%29
=)
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 |
---|---|---|
17.1.2 | 82 | 12/30/2024 |
17.1.1 | 75 | 12/30/2024 |
17.1.0 | 66 | 12/30/2024 |
17.0.2 | 73 | 12/24/2024 |
16.1.2 | 78 | 12/22/2024 |
16.1.1 | 79 | 12/21/2024 |
16.1.0 | 80 | 12/20/2024 |
16.0.4 | 99 | 12/18/2024 |
16.0.3 | 85 | 12/18/2024 |
16.0.0 | 96 | 12/18/2024 |
15.3.4 | 194 | 12/7/2024 |
15.3.3 | 89 | 12/7/2024 |
15.3.2 | 92 | 12/7/2024 |
15.3.1 | 95 | 12/7/2024 |
15.3.0 | 100 | 12/6/2024 |
15.2.4 | 107 | 12/6/2024 |
15.2.3 | 109 | 12/6/2024 |
15.1.7 | 233 | 7/15/2024 |
15.1.6 | 179 | 6/11/2024 |
15.1.5 | 190 | 3/26/2024 |
15.1.4 | 129 | 3/26/2024 |
15.1.3 | 216 | 3/11/2024 |
15.1.2 | 150 | 3/8/2024 |
15.1.1 | 175 | 3/4/2024 |
15.1.0 | 156 | 2/28/2024 |
15.0.1 | 127 | 2/22/2024 |
15.0.0 | 172 | 2/20/2024 |
14.0.5 | 151 | 2/19/2024 |
14.0.4 | 100 | 2/19/2024 |
14.0.3 | 109 | 2/19/2024 |
14.0.2 | 139 | 2/15/2024 |
14.0.0 | 136 | 2/15/2024 |
14.0.0-alpha.30 | 67 | 2/15/2024 |
14.0.0-alpha.29 | 60 | 2/15/2024 |
14.0.0-alpha.28 | 62 | 2/15/2024 |
14.0.0-alpha.27 | 65 | 2/15/2024 |
14.0.0-alpha.26 | 69 | 2/15/2024 |
14.0.0-alpha.25 | 67 | 2/15/2024 |
14.0.0-alpha.24 | 71 | 2/15/2024 |
14.0.0-alpha.22 | 67 | 2/15/2024 |
14.0.0-alpha.20 | 71 | 2/15/2024 |
13.0.0 | 231 | 1/8/2024 |
12.1.2 | 166 | 1/6/2024 |
12.1.1 | 149 | 1/6/2024 |
12.1.0 | 137 | 1/6/2024 |
12.0.9 | 181 | 1/5/2024 |
12.0.8 | 163 | 1/5/2024 |
11.0.0 | 163 | 12/16/2023 |
8.0.3 | 142 | 12/11/2023 |
8.0.2 | 160 | 12/11/2023 |
8.0.0 | 189 | 12/11/2023 |