2025-10-03 02:10:17 +08:00
|
|
|
using System.Text;
|
|
|
|
|
using Microsoft.CodeAnalysis;
|
|
|
|
|
using Microsoft.CodeAnalysis.Text;
|
|
|
|
|
|
|
|
|
|
namespace MySourceGenerator {
|
|
|
|
|
[Generator]
|
|
|
|
|
public class MySourceGenerator : ISourceGenerator {
|
|
|
|
|
public void Execute(GeneratorExecutionContext context) {
|
|
|
|
|
var sb = new StringBuilder();
|
|
|
|
|
sb.AppendLine("using System;");
|
|
|
|
|
sb.AppendLine("namespace Generated;");
|
|
|
|
|
sb.AppendLine("public static class HelloWorld {");
|
2025-10-03 19:37:52 +08:00
|
|
|
sb.AppendLine(" public static string SayHello() {");
|
|
|
|
|
sb.AppendLine(" return \"Hello World!!!\";");
|
2025-10-03 02:10:17 +08:00
|
|
|
sb.AppendLine(" }");
|
|
|
|
|
sb.AppendLine("}");
|
|
|
|
|
|
|
|
|
|
context.AddSource("HelleWorld.generated", SourceText.From(sb.ToString(), Encoding.UTF8));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Initialize(GeneratorInitializationContext context) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|