Skip to main content
deleted 26 characters in body
Source Link
winscripter
  • 890
  • 3
  • 7
  • 40

Based on some now-deleted comments, I figured out that the exact equivalent of this:

[Generator]
public class Sample : ISourceGenerator
{
    public void Execute(GeneratorExecutionContext context)
    {
        context.AddSource("Foo.g.cs", "public class Bar { }");
    }

    public void Initialize(GeneratorInitializationContext context)
    {
    }
}

would be:

[Generator(LanguageNames.CSharp)]
public class Sample : IIncrementalGenerator
{
    public void Initialize(IncrementalGeneratorInitializationContext context)
    {
        string sourceCode = ...;
        context.RegisterPostInitializationOutput(ctx => ctx.AddSource(
                "FileName.g.cs", SourceText.From(sourceCode, Encoding.UTF8)));
    }
}

It seems like the oldprevious source generators are now deprecated in a way that we cannot use them anymore. The only type of source generators we can use today are incremental source generators. The exact equivalent works because it's an incremental source generator, not an "old source generator".

Additionally, see this markdown file on GitHub and this article by Andrew Lock.

Note: Links in answer were also provided by comments which are now deleted.

Based on some now-deleted comments, I figured out that the exact equivalent of this:

[Generator]
public class Sample : ISourceGenerator
{
    public void Execute(GeneratorExecutionContext context)
    {
        context.AddSource("Foo.g.cs", "public class Bar { }");
    }

    public void Initialize(GeneratorInitializationContext context)
    {
    }
}

would be:

[Generator(LanguageNames.CSharp)]
public class Sample : IIncrementalGenerator
{
    public void Initialize(IncrementalGeneratorInitializationContext context)
    {
        string sourceCode = ...;
        context.RegisterPostInitializationOutput(ctx => ctx.AddSource(
                "FileName.g.cs", SourceText.From(sourceCode, Encoding.UTF8)));
    }
}

It seems like the old source generators are now deprecated in a way that we cannot use them anymore. The only type of source generators we can use today are incremental source generators. The exact equivalent works because it's an incremental source generator, not an "old source generator".

Additionally, see this markdown file on GitHub and this article by Andrew Lock.

Note: Links in answer were also provided by comments which are now deleted.

Based on some now-deleted comments, I figured out that the exact equivalent of this:

[Generator]
public class Sample : ISourceGenerator
{
    public void Execute(GeneratorExecutionContext context)
    {
        context.AddSource("Foo.g.cs", "public class Bar { }");
    }

    public void Initialize(GeneratorInitializationContext context)
    {
    }
}

would be:

[Generator(LanguageNames.CSharp)]
public class Sample : IIncrementalGenerator
{
    public void Initialize(IncrementalGeneratorInitializationContext context)
    {
        string sourceCode = ...;
        context.RegisterPostInitializationOutput(ctx => ctx.AddSource(
                "FileName.g.cs", SourceText.From(sourceCode, Encoding.UTF8)));
    }
}

It seems like the previous source generators are now deprecated in a way that we cannot use them anymore. The only type of source generators we can use today are incremental source generators. The exact equivalent works because it's an incremental source generator.

Additionally, see this markdown file on GitHub and this article by Andrew Lock.

Note: Links in answer were also provided by comments which are now deleted.

Source Link
winscripter
  • 890
  • 3
  • 7
  • 40

Based on some now-deleted comments, I figured out that the exact equivalent of this:

[Generator]
public class Sample : ISourceGenerator
{
    public void Execute(GeneratorExecutionContext context)
    {
        context.AddSource("Foo.g.cs", "public class Bar { }");
    }

    public void Initialize(GeneratorInitializationContext context)
    {
    }
}

would be:

[Generator(LanguageNames.CSharp)]
public class Sample : IIncrementalGenerator
{
    public void Initialize(IncrementalGeneratorInitializationContext context)
    {
        string sourceCode = ...;
        context.RegisterPostInitializationOutput(ctx => ctx.AddSource(
                "FileName.g.cs", SourceText.From(sourceCode, Encoding.UTF8)));
    }
}

It seems like the old source generators are now deprecated in a way that we cannot use them anymore. The only type of source generators we can use today are incremental source generators. The exact equivalent works because it's an incremental source generator, not an "old source generator".

Additionally, see this markdown file on GitHub and this article by Andrew Lock.

Note: Links in answer were also provided by comments which are now deleted.