3
This commit is contained in:
@@ -6,16 +6,11 @@ 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 {");
|
||||
sb.AppendLine(" public static string SayHello() {");
|
||||
sb.AppendLine(" return \"Hello World!!!\";");
|
||||
sb.AppendLine(" }");
|
||||
sb.AppendLine("}");
|
||||
|
||||
context.AddSource("HelleWorld.generated", SourceText.From(sb.ToString(), Encoding.UTF8));
|
||||
var template = context.AdditionalFiles.Where(static file => file.Path.EndsWith("HelloWorld.template.cs")).First().GetText()?.ToString();
|
||||
if (template == null) {
|
||||
return;
|
||||
}
|
||||
context.AddSource("HelleWorld.generated", SourceText.From(template, Encoding.UTF8));
|
||||
}
|
||||
|
||||
public void Initialize(GeneratorInitializationContext context) {
|
||||
|
||||
Reference in New Issue
Block a user