Enhanced Support for Required Init-Only Properties with Object Initializers #8137
Unanswered
nyan-cat
asked this question in
Language Ideas
Replies: 2 comments 9 replies
-
IIRC, |
Beta Was this translation helpful? Give feedback.
1 reply
-
I definitely would like to see an augmentation of So, an array parameter could be provided that calls out the subset: [SetsRequiredMembers("FirstName")] // `LastName` is not set |
Beta Was this translation helpful? Give feedback.
8 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Good day!
I have a request to improve how required init-only properties work with object initializers. The current
SetsRequiredMembers
attribute helps, but it disables compile-time checks for required properties.Feature Request
Enhance C# to ensure all required init-only properties are initialized when using object initializers, without needing SetsRequiredMembers.
Example
With
SetsRequiredMembers
, Id isn't checked as required. I want the compiler to enforce that all required properties are set. In fact, we just don't needSetsRequiredMembers
, we should be able to delegate requireds to the caller of the record constructor.Thanks for considering this request!
Beta Was this translation helpful? Give feedback.
All reactions