Extending partial file-local type with source generatrors

28 Views Asked by At

I was curious if it would be possible for a Source Generator to extend a partial file-local type such as:

namespace Bar;

file partial class Foo
{
    // Omitted for brevity...
}

I tried to output the following code snippet in the RegisterSourceOutput method:

ctx.AddSource("Foo.cs", 
"""
namespace Bar;
    
file partial class Foo
{
    public int FooBar { get; set; }
}
""");

Note that the generated hint name is the same as the "target" file name. Anyhow, with IL Spy I can see that it generates two types which look something like this:

internal class <Foo>FFC769A3FDE8D9AC06720D6E176DDEAEFDBCA21D74E682A2556B5EC23F5D641E3__Foo

Instead of a single one, which Is what I am trying to achieve.

0

There are 0 best solutions below