You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Treat .NET 7 required properties as actually required by default #862
What if you have a required modifier and [Option(Required = false)]? I would say, it should throw because of conflicting settings. Please add test for such case
Required = false is the default case, hence, if we implement this, it will throw on default case.
We can make Required = true mandatory on required properties, which is redundant and against the purpose of this issue (Treat .NET 7 required properties as actually required by default).
We can change the type of the Required attribute property to a try-state (unset, true, false) with an unset default value, which will be treated:
as true in the case of a required property
as false in other cases
We can stay silent and ignore Required = false on required properties.
Option 2 looks pretty, but we must validate that it is not a breaking change (see this Jon Skeet post where he talk about the optional parameters). Does a bool? do the trick?
Required = false is the default case, hence, if we implement this, it will throw on default case.
Uh, I see...
Does a bool? do the trick?
Having Required as a bool? can really be a win, so we infer null state to true if the property is required and false otherwise. I am afraid, this is a binary breaking change though...
Activity
Orace commentedon Dec 12, 2022
Using sharplab.io, it appears that a RequiredMemberAttribute is added to the
requiredproperties.Search for this attribute is a trivia.
Orace commentedon Dec 13, 2022
Has mentioned by DoctorKrolic here
Required = falseis the default case, hence, if we implement this, it will throw on default case.We can make
Required = truemandatory onrequiredproperties, which is redundant and against the purpose of this issue (Treat .NET 7 required properties as actually required by default).We can change the type of the
Requiredattribute property to a try-state (unset,true,false) with anunsetdefault value, which will be treated:truein the case of arequiredpropertyfalsein other casesWe can stay silent and ignore
Required = falseonrequiredproperties.Option 2 looks pretty, but we must validate that it is not a breaking change (see this Jon Skeet post where he talk about the optional parameters). Does a
bool?do the trick?DoctorKrolic commentedon Dec 13, 2022
Uh, I see...
Having
Requiredas abool?can really be a win, so we infernullstate totrueif the property isrequiredandfalseotherwise. I am afraid, this is a binary breaking change though...Orace commentedon Dec 13, 2022
A quick look to the IL shows it unfortunately is 😒