Please provide us more ways or easier ways to horizontal code reuse #8863
Replies: 5 comments 62 replies
-
Source generators are definitely the solution for automatically pasting a bunch of templated source into your code. If you're having specific issues with source generators they can be considered and addressed through improvements or documentation, but the language isn't going to start adding templating features because of that. |
Beta Was this translation helpful? Give feedback.
-
@HaloFour. Let's consider the partial class as you told me here. I worked with it and it actually solved my problem. I have a And as I told you here I created a simple com+poser in Python to compose my C# partial class from snippet files. Well, it worked great. I even shipped the code to the production and it is under load right now and works great. Yet there is a problem with that approach. It's blind. I don't have access to the AST or CST anymore. I can't make smart decisions when com+posing the code. So I have to either come back to the source generation, or another method. I would appreciate it if you could improve the DX of source generation. Can I tell you one by one? |
Beta Was this translation helpful? Give feedback.
-
@HaloFour, can I start from here: Why can't I create source generators, as part of my current source code? Inside a directory. Let's start from there. What prevents the .NET team to distinguish source generators from the remaining code, and run it in the pipeline? |
Beta Was this translation helpful? Give feedback.
-
The next thing that I have in mind for simplification is merging the I want to add Why should I create a syntax receiver and add them to a collection separately, then register that receiver, then check the type of the receiver and then loop over them? Can't I just register a node visitor and on each visit, generate the code? In other words, instead of this:
Why can't I just have:
All I'm saying is that what I want is to find out nodes and act based on them. Why can't I just do that in one class? Even if you prefer or have to keep them separately, give us a combined experience in a super interface or orchestrator interface. An interface called |
Beta Was this translation helpful? Give feedback.
-
Another simplification. Can you provide some common source generation scenarios out of the box? I compare the source generation to ASP.NET. In ASP.NET we do have a lot of goodies out of the box, like some middleware classes that we can use and if we want something more, then we should customize. Can you provide some source generators out of the box? For example, it would be great to have this attribute, out of the box:
Can you think of some common needs that people solve using source generation? And if we can get a list, then we might be able to piche the top 10 needs and create source generators for them. That would be very useful. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have discussed codes similar to this before:
From those discussions, I ended up deciding that the only way I have is to use source generation. Yet source generation is extremely difficult as a way for horizontal code reuse. Instead of a simple
include
statement, we should do what not to add a bunch of methods to a given class. It works but with the current complexity, it's not truly affordable. The learning curve, debugging pain, separate tech, wiring headaches, and other problems reduce its true feasibility.Can you simplify horizontal code reuse or add new ways for it?
Beta Was this translation helpful? Give feedback.
All reactions