OneOf icon indicating copy to clipboard operation
OneOf copied to clipboard

Source generator should work for nested types

Open dstockhammer opened this issue 1 year ago • 1 comments

It looks like the source generator doesn't work for nested classes.

works as expected

[GenerateOneOf]
public partial class Result : OneOfBase<string, string> {}

does not work

public class MyClass {
    [GenerateOneOf]
    public partial class Result : OneOfBase<string, string> {}
}

Or am I doing something wrong? I'm no expert with source generators, but I believe it should be possible to configure the generator to pick up nested types too.

Thanks!

dstockhammer avatar Jul 09 '22 10:07 dstockhammer

source generator simply generates new .cs files and you cant generate file that matches this:

public class MyClass 
{
    [GenerateOneOf]
    public partial class Result : OneOfBase<string, string> {}
}

for example this code does not compile:

public class A
{

	public partial class B { }
}

public class A
{

	public partial class B { }
}

it would result in compile time error. it could theoretically be possible to generate a matching file when class is nested in another partial class eg:

public partial class MyClass 
{
    [GenerateOneOf]
    public partial class Result : OneOfBase<string, string> {}
}

but for simplicity it was not done :)

romfir avatar Jul 12 '22 21:07 romfir