Skip to content

Commit a43802e

Browse files
committed
Fix typos and link in Source Generators cookbook
Improve mention of IDE experience scenario so that it links to it. Acknowledge trailing JSON comma. Fix FileTransformGenerator example indent.
1 parent 0196341 commit a43802e

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

docs/features/source-generators.cookbook.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -115,26 +115,26 @@ namespace GeneratedNamespace
115115
```csharp
116116
[Generator]
117117
public class FileTransformGenerator : ISourceGenerator
118-
{
119-
public void Initialize(InitializationContext context) {}
118+
{
119+
public void Initialize(InitializationContext context) {}
120120

121-
public void Execute(SourceGeneratorContext context)
121+
public void Execute(SourceGeneratorContext context)
122+
{
123+
// find anything that matches our files
124+
var myFiles = context.AnalyzerOptions.AdditionalFiles.Where(at => at.Path.EndsWith(".xml"));
125+
foreach (var file in myFiles)
122126
{
123-
// find anything that matches our files
124-
var myFiles = context.AnalyzerOptions.AdditionalFiles.Where(at => at.Path.EndsWith(".xml"));
125-
foreach (var file in myFiles)
126-
{
127-
var content = file.GetText(context.CancellationToken);
127+
var content = file.GetText(context.CancellationToken);
128128

129-
// do some transforms based on the file context
130-
string output = MyXmlToCSharpCompiler.Compile(content);
129+
// do some transforms based on the file context
130+
string output = MyXmlToCSharpCompiler.Compile(content);
131131

132-
var sourceText = SourceText.From(output, Encoding.UTF8);
132+
var sourceText = SourceText.From(output, Encoding.UTF8);
133133

134-
context.AddSource($"{file.Name}generated.cs", sourceText);
135-
}
134+
context.AddSource($"{file.Name}generated.cs", sourceText);
136135
}
137136
}
137+
}
138138
```
139139

140140
### Augment user code
@@ -628,7 +628,7 @@ partial class MyRecord
628628
}
629629
```
630630

631-
This attribute could also be used for #participate-in-the-ide-experience,
631+
This attribute could also be used for [Participate in the IDE experience](#participate-in-the-ide-experience),
632632
when the full scope of that feature is fully designed. In that scenario,
633633
instead of the generator finding every type marked with the given attribute,
634634
the compiler would notify the generator of every type marked with the given
@@ -670,8 +670,8 @@ public string Serialize()
670670
```
671671

672672
Obviously this is heavily simplified -- this example only handles the `string` and `int`
673-
types properly and has no error recovery, but it should serve to demonstrate the kind
674-
of code a source generator could add to a compilation.
673+
types properly, adds a trailing comma to the json output and has no error recovery, but
674+
it should serve to demonstrate the kind of code a source generator could add to a compilation.
675675

676676
Our next task is design a generator to generate the above code, since the
677677
above code is itself customized in the `// Body` section according to the

0 commit comments

Comments
 (0)