-
Notifications
You must be signed in to change notification settings - Fork 60
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
WrapperValueObject source generator #17
Comments
Thanks @YairHalberstadt! Very simple but definitely cool. It demonstrates an additional area in which source generators can be used, for generating types with a predefined structure. A kind of a C# 9.0 It reminds me also of @andrewlock's excellent article series Using strongly-typed entity IDs to avoid primitive obsession and his StronglyTypeId project. WrapperValueObject is still in a very early I would say PoC stage but demonstrate well an additional area of source generators usage so I would like to add it to the Awesome Roslyn list. @YairHalberstadt would you mind contributing and creating a pull request? |
Excellent! I tried out a simple PoC of this a while ago, that looked almost exactly like this 🙂 Couldn't be more timely, seeing as the build for my StrongTypedId project seems to have imploded in an SDK update at some point 😫 |
@andrewlock although you've mentioned in the last article in the series that you do not see a value in porting StronglyTypedId to source generators, I would love to see that happening. The existing implementation is great and also the whole series of blog posts is the best read on the topic I came across. Having a C# 9.0 source generator of that quality would be great. On the other hand, I would equally love to see @martinothamar's WrapperValueObject moving beyond the PoC, getting maybe cleaner API, Nuget package etc. At the moment it is a combination of a strongly typed id and an immutable struct generator. Anyhow, thank you both for your inspiring work! :-) |
WrapperValueObject proof-of-concept demonstrates very well how source generators can be used for generating types of a predefined structure like immutable structs, strongly typed ids and similar. Fixes #17.
Hey! Cool, thanks for the mention
My original motivation was simplifying lots of boilerplate related to value object structs in a previous project, but I also ended up at this exact conclusion - it's basically record feature for structs 🙂 C# 9 only comes with the record feature for classes thus far AFAIK, is that still correct? Do you know if there has been any consideration for doing it also for structs in the future? The .NET guidance for defining structs is to always implement
Indeed it is, haven't used this much yet. But since it got some interest I'll add some polish and get a proper nuget package out. Suggestions etc are welcome 👍 |
For me my main usage would be creating strongly typed wrappers for primitives - eg. I think you already generate all that, but some documentation on what's generated would be useful! |
That's planned for C# 10 |
That was my usecase as well, awesome, will put in some docs work and publish 👍 |
I'd be keen to retire my StronglyTypedId package in favour of your source generator version too - my intention was to rewrite StronglyTypedId using source gens once it went GA, but looks like you've saved me the trouble 😀 There may be space for both of them, serving slightly different goals, but we'll see - if I can get away using yours that sounds good to me 🙂 |
My suggestion (I hope I am not shooting too far :-)) is to bring WrapperValueObject to a production level and to have the strongly typed ids as one of the supported use cases:
|
@ironcev that sounds good to me, I can try to get there and maybe @andrewlock can review eventually, then we can see how it works out. I'm open to any solution, and agree with the usecases here 🙂 |
Hi again, I have pushed some updates
Other than that not quite sure on how to improve the API/Attribute(s). Been thinking of maybe having 1 attribute per primitive type for example - |
Looks good, thanks for your commitment @martinothamar :-) Regarding the API improvements and other ideas, I propose to move the discussion to the WrapperValueObject repository and use dedicated GitHub issues for that. I am interested in seeing the project getting developed further and can formulate the proposals more precisely in GitHub issues. That way it will be much easier to discuss and refine them one by one. |
Saw this - thought it looked cool and you might be interested https://github.com/martinothamar/WrapperValueObject
The text was updated successfully, but these errors were encountered: