"Generator Source Addition Example"

[Generator]
public class MySourceGenerator : ISourceGenerator {
	const string ExampleSource = @"
		namespace GeneratedNamespace {
			public static class GeneratedClass {
				public static void SayHello() => System.Console.WriteLine(""Hello"");
			}
		}";

	public void Execute(GeneratorExecutionContext context) {
		context.AddSource("Generated.cs", ExampleSource);
	}

	public void Initialize(GeneratorInitializationContext context) {
		/* do nothing */
	}
}


Code snippet taken from "Two Decades of C#: A Reference - C# 9".