diff --git a/docs/features/generators.md b/docs/features/generators.md index e8ee7b73ea5313978a97569c67d2023b7c8bff6f..05d261cd6245485da9ec1e9f909000826116ad43 100644 --- a/docs/features/generators.md +++ b/docs/features/generators.md @@ -21,7 +21,7 @@ Scenarios General ------- Source generators are implementations of `Microsoft.CodeAnalysis.SourceGenerator`. -``` +```csharp public abstract class SourceGenerator { public abstract void Execute(SourceGeneratorContext context); @@ -42,7 +42,7 @@ the assembly in which it is defined. `SourceGenerator` has a single `Execute` method that is called by the host -- either the IDE or the command-line compiler. `Execute` provides access to the `Compilation` and allows adding source and reporting diagnostics. -``` +```csharp public abstract class SourceGeneratorContext { public abstract Compilation Compilation { get; } @@ -74,7 +74,7 @@ Source generators are executed by the command-line compilers and the IDE. The ge are obtained from the `AnalyzerReference.GetSourceGenerators` for each analyzer reference specified on the command-line or in the project. `GetSourceGenerators` uses reflection to find types that inherit from `SourceGenerator` and instantiates those types. -``` +```csharp public abstract class AnalyzerReference { ... @@ -87,7 +87,7 @@ and returns the collection of `SyntaxTrees` and `Diagnostics`. (`GenerateSource` is called by the command-line compilers and IDE.) If `writeToDisk` is true, the generated source is persisted to `outputPath`. Regardless of whether the tree is persisted to disk, `SyntaxTree.FilePath` is set. -``` +```csharp public static class SourceGeneratorExtensions { public static ImmutableArray GenerateSource( @@ -121,8 +121,8 @@ To redefine members in generated source, there are new language keywords: `repla `replace` and `original` are contextual keywords: `replace` is a keyword only when used as a member modifier; `original` is a keyword only when used within a `replace` method (similar to parser handling of `async` and `await`). -``` -original.cs: +```csharp +// original.cs: partial class C { void F() { } @@ -131,7 +131,7 @@ original.cs: event EventHandler E; } -replace.cs: +// replace.cs: partial class C { replace void F() { original(); }