8000 Source generators for command handlers by Keboo · Pull Request #1362 · dotnet/command-line-api · GitHub
[go: up one dir, main page]

Skip to content

Source generators for command handlers #1362

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

Merged
merged 39 commits into from
Sep 14, 2021
Merged

Conversation

Keboo
Copy link
Member
@Keboo Keboo commented Jul 28, 2021

This is a proof-of-concept just to solicit feedback. It is not a complete solution (yet?).

This leverages source generators to automatically build up command handlers.
The most interesting part of the solution is the GeneratedCommandHandlerTests.cs. This contains the tests to show how this works. Currently this adds in a new Generator property on the CommandHandlers class. This class is meaningless on its own, and only used as an anchor point for the source generator to look for. There are a couple "Generate" extension methods on this class (it is key that they are extension methods). When the generator sees a call to those Generate methods its generates a new extension method with better parameter matching to ensure that it will always be the one resolved. This is how it is able to build up the handlers at compile time.

There are lots of known failure cases, lots of things that have not been handled, and the source generator code is a mess.

Looking to know if this is an idea that is interesting enough to pursue and feedback on the approach.

Copy link
Contributor
@KathleenDollard KathleenDollard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow! Can we meet to go over this. I love the idea but got lost in so much code and would like to work back from the code we are aiming for.

I'd like to ensure this plays nice with models as I think you'll like the most recent model I'm working on.

@Keboo
Copy link
Member Author
Keboo commented Aug 2, 2021

@KathleenDollard yes I would would love to get together to go over this. My next steps are going to be to handle some of the error cases, and replace the C# string building.
Jon had suggested getting this decoupled from the main core lib so it could be released separately to let people try it out and report issues, so I will also work on getting that moved.

@jonsequitur jonsequitur merged commit 49de0fd into dotnet:main Sep 14, 2021
@Keboo Keboo deleted the generatorMaybe branch September 14, 2021 20:09
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

Successfully merging this pull request may close these issues.

3 participants
0