Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source generator should work for nested types #125

Open
dstockhammer opened this issue Jul 9, 2022 · 1 comment
Open

Source generator should work for nested types #125

dstockhammer opened this issue Jul 9, 2022 · 1 comment

Comments

@dstockhammer
Copy link

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!

@romfir
Copy link
Contributor

romfir commented Jul 12, 2022

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants