-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathGenerator.cs
33 lines (30 loc) · 1.23 KB
/
Generator.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using System.Text;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Text;
using Scriban;
using SuperLinq.Generator;
namespace SuperLinq.Async.Generator;
/// <summary>
/// Uses source generation tools to automate the building of some operators
/// </summary>
[Generator]
public class Generator : IIncrementalGenerator
{
/// <inheritdoc />
public void Initialize(IncrementalGeneratorInitializationContext context)
{
context.RegisterPostInitializationOutput(ctx => ctx.AddSource(
"EquiZip.g.cs", GenerateArgumentNamesTemplate(ThisAssembly.Resources.EquiZip.Text)));
context.RegisterPostInitializationOutput(ctx => ctx.AddSource(
"Fold.g.cs", GenerateArgumentNamesTemplate(ThisAssembly.Resources.Fold.Text)));
context.RegisterPostInitializationOutput(ctx => ctx.AddSource(
"ZipLongest.g.cs", GenerateArgumentNamesTemplate(ThisAssembly.Resources.ZipLongest.Text)));
context.RegisterPostInitializationOutput(ctx => ctx.AddSource(
"ZipShortest.g.cs", GenerateArgumentNamesTemplate(ThisAssembly.Resources.ZipShortest.Text)));
}
private static SourceText GenerateArgumentNamesTemplate(string template)
{
var output = Template.Parse(template).Render(ArgumentNames.Instance);
return SourceText.From(output, Encoding.UTF8);
}
}