-
Notifications
You must be signed in to change notification settings - Fork 12
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
Nullable values #6
Comments
@hhenrik08 did you define the parameter as |
Hi @dasMulli, sorry for picking up this topic again after such a long time. I might have a few insights on this, though. There's a subtlety around nullable value types in C# that I only learned about a few hours ago. Apparently, the compiler behaves somewhat counter-intuitive (from my perspective this even looks like a bug in the language, but I might be missing something) when using the default literal. This test shows what I mean. My expectation would be that the variables
How does this relate to this issue? As far as I can see, the data-builder-generator will generate slightly different If a nullable value type is included in a constructor however, the
I am aware, this is not primarily a data-builder-generator issue, but I am wondering if you'd be open to hiding this behaviour from the user, as it makes the usage rather error-prone. I have drafted a PR to switch from default literals to explicit default operators in the constructor call of Thanks for this nice package and all your work. Best regards For reference: there have been discussions on the behaviour of the default literal which led me to thinking this was regarded as a bug and has been fixed since language version 7.2. From what I can see today, though, I believe there are still issues around default literal usages. (see dotnet/csharplang#970) |
In this case In this case any You could open another issue on csharplang to discuss this. I agree that this seems counterintuitive. |
Thanks for looking into this so quickly! I will try to follow up with the discussion over on csharplang. What's your take on #10? Do you think it would be reasonable to change the way that data-builder-generator handles the constructor calls to make the behaviour more predictable? |
Hi there! I’m a big fan of your data builder generator!
I’m just having one small issue when working with nullable types. Since I like my classes to be immutable, I’m using constructors for all parameters, including those that may actually be null.
When using your generator with e.g. a nullable int, the generated code calls the constructor in the following way (excluding null checks):
Unfortunately, the default seems to be the default value for int-types, so I never actually get
null
when creating the class, as these are replaced by the value “0”.Do you think that is something you could fix? I Would offer to look into it myself, but I doubt my experience will be sufficient to fix this.
Cheers!
Henrik
The text was updated successfully, but these errors were encountered: