-
Notifications
You must be signed in to change notification settings - Fork 59
Question: Is it possible to create a new class from an attribute that targets methods? #236
Comments
Yes, it's possible. We have a simple codegen endpoint which is apparently what you tried, which puts you in the same (partial) class. But we have a more "I own everything" endpoint that lets you generate the entire CompilationUnit (source file). |
Hi, SuggestionBut first, let me suggest to you the new C# Source Generators feature shipping with .NET 5/C#9: https://devblogs.microsoft.com/dotnet/introducing-c-source-generators/ The development experience currently is actually a bit worse compared to CG.R, but the future is there (we won't be pursuing CodeGeneration.Roslyn development any further). AnswerIndeed there's no mention in README of the required feature - it's only described a little bit in https://github.com/AArnott/CodeGeneration.Roslyn/wiki/Features#irichcodegenerator
|
For simplicity assume my goal is to have an attribute on a method that generates a new class whose name is the methods names followed by "Wrapper".
For example if I have an attribute:
And a class:
I would want to generate the following class:
Of course I tried this with my crude understanding of code generation using this code in my generator:
Which generates:
This is close to what I want but being nested under
TestClass
causes a build error because I now have 2 definitions ofTestClass
. I feel like there must be a way to accomplish my goal of creating a completely new (ie. not a class nested in another class).Is this possible? If so, how?
I really appreciate any help on this 😄
The text was updated successfully, but these errors were encountered: