Replies: 1 comment 6 replies
-
In fact we didn't think about default being uninitialized for immutable collections. |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey, not sure if this is supported behaviour I can't spot anything in the docs. There is something I would consider an issue with ImmutableArray (may be the same with other immutable types) where
ImmutableArray<int> x = default
is not the same as setting it to empty, and has the tendency to throw runtime exceptions if the devs don't deal with it correctly.This extra trick when using this type in an API request where the API model might be null but the internal can't be null. When mapping the code is generating something like this;
Is there a way to easily configure the default/null behaviour for a given types so it generates something like;
This would save some potential explosions if our tests don't catch the issue.
I know this could possibly be caught with some validation on the incoming request but in this case it's not something we can do.
#250 is where this feature was implemented but this was not raised.
This could be to do with how we are dealing with nulls possible something similar to how Newtonsoft handles this with
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
. Would you be open to expanding how the null behaviour is used so haveing something like;Where the mapper would not set the value on the target if the source is null? This would allow our domain model to deal with it, in this case we set it to empty instead of default. This works fine with json but has an issue with the mapper as shown in the generated code using default.
Beta Was this translation helpful? Give feedback.
All reactions