Skip to content

Commit 37c1482

Browse files
committed
extract Emit method
1 parent d897c89 commit 37c1482

2 files changed

Lines changed: 18 additions & 14 deletions

File tree

src/StringLiteralGenerator/Utf8StringLiteralGenerator.Emitter.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,29 @@
11
using Microsoft.CodeAnalysis;
2+
using Microsoft.CodeAnalysis.Text;
23
using System;
34
using System.Collections.Generic;
5+
using System.Linq;
46
using System.Text;
57

68
namespace StringLiteralGenerator;
79

810
public partial class Utf8StringLiteralGenerator : ISourceGenerator
911
{
12+
private static void Emit(GeneratorExecutionContext context, IEnumerable<Utf8LiteralMethod> methods)
13+
{
14+
var buffer = new StringBuilder();
15+
16+
var group = methods.GroupBy(x => x.Type, x => x.Method);
17+
18+
foreach (var g in group)
19+
{
20+
var containingType = g.Key;
21+
var generatedSource = Generate(containingType, g, buffer);
22+
var filename = GetFilename(containingType, buffer);
23+
context.AddSource(filename, SourceText.From(generatedSource, Encoding.UTF8));
24+
}
25+
}
26+
1027
private static string GetFilename(TypeInfo type, StringBuilder buffer)
1128
{
1229
buffer.Clear();

src/StringLiteralGenerator/Utf8StringLiteralGenerator.cs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
using Microsoft.CodeAnalysis;
22
using Microsoft.CodeAnalysis.CSharp.Syntax;
3-
using Microsoft.CodeAnalysis.Text;
43
using System.Collections.Generic;
5-
using System.Linq;
6-
using System.Text;
74

85
namespace StringLiteralGenerator;
96

@@ -16,17 +13,7 @@ public void Execute(GeneratorExecutionContext context)
1613

1714
var compilation = context.Compilation;
1815

19-
var buffer = new StringBuilder();
20-
21-
var group = enumerate().GroupBy(x => x.Type, x => x.Method);
22-
23-
foreach (var g in group)
24-
{
25-
var containingType = g.Key;
26-
var generatedSource = Generate(containingType, g, buffer);
27-
var filename = GetFilename(containingType, buffer);
28-
context.AddSource(filename, SourceText.From(generatedSource, Encoding.UTF8));
29-
}
16+
Emit(context, enumerate());
3017

3118
IEnumerable<Utf8LiteralMethod> enumerate()
3219
{

0 commit comments

Comments
 (0)