Giter VIP home page Giter VIP logo

Comments (12)

ironcev avatar ironcev commented on May 24, 2024 2

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

from awesome-roslyn.

andrewlock avatar andrewlock commented on May 24, 2024 2

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 🙂

from awesome-roslyn.

martinothamar avatar martinothamar commented on May 24, 2024 2

@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 🙂

from awesome-roslyn.

martinothamar avatar martinothamar commented on May 24, 2024 2

Hi again, I have pushed some updates

  • Improved README
  • NuGet package
  • More tests (still more needed)
  • Support more of StronglyTypedId functionality (JsonConverter is the remaining piece I think)

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 - IntWrapperType, FloatWrapperType etc. Some of the code that is being generated should probably also be configurable, for instance maybe you don't want implicit casts. But I think this is an OK start at least.

from awesome-roslyn.

ironcev avatar ironcev commented on May 24, 2024 1

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 record feature for structs in this case ;-)

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?

from awesome-roslyn.

YairHalberstadt avatar YairHalberstadt commented on May 24, 2024 1

Do you know if there has been any consideration for doing it also for structs in the future?

That's planned for C# 10

from awesome-roslyn.

ironcev avatar ironcev commented on May 24, 2024 1

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.

from awesome-roslyn.

andrewlock avatar andrewlock commented on May 24, 2024

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 😫

from awesome-roslyn.

martinothamar avatar martinothamar commented on May 24, 2024

Hey! Cool, thanks for the mention

A kind of a C# 9.0 record feature for structs in this case ;-)

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 GetHashCode and Equals AFAIK since if equality/hashcode is used in any way without those implementations it will have massive performance implications (experienced this in production once)

WrapperValueObject is still in a very early I would say PoC stage

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 👍

from awesome-roslyn.

YairHalberstadt avatar YairHalberstadt commented on May 24, 2024

@martinothamar

For me my main usage would be creating strongly typed wrappers for primitives - eg. MetersLength which wraps int, and can be implicitly cast between the two.

I think you already generate all that, but some documentation on what's generated would be useful!

from awesome-roslyn.

martinothamar avatar martinothamar commented on May 24, 2024

That was my usecase as well, awesome, will put in some docs work and publish 👍

from awesome-roslyn.

ironcev avatar ironcev commented on May 24, 2024

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:

  • Improve API:
    • Replace one generic attribute (WrapperValueObject) with two (or more) that cleary identify the usecase. E.g. StronglyTypedIdAttribute, ImmutableStructAttribute, ...
  • Support everything that StronglyTypedId supports (e.g. optional generation of JSON converters).
  • Bring the documentation to the same level as in the StronglyTypedId project.
  • Write tests.
  • Create Nuget package.

from awesome-roslyn.

Related Issues (5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.