Add an attribute to indicate a property won't return null even if it isn't set after initialization. #4467
Unanswered
JustNrik
asked this question in
Language Ideas
Replies: 2 comments 9 replies
-
It would be |
Beta Was this translation helpful? Give feedback.
4 replies
-
Such code is quite anti-pattern for nullable initialization. |
Beta Was this translation helpful? Give feedback.
5 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.
-
Sometimes we want to expose a class that we know they have properties that won't return null, but these properties aren't set during initialization but later, but guaranteed to be set before exposed to the user.
Example:
Currently:
Suggestion: Add an attribute for this case, something like LateInitialized? or WillNotBeNull or Idk I really haven't come up with a good naming.
Current work arounds
[AllowNull]
to the property: It works, but it doesn't show the intentions clear. I wish there was an attribute specifically for this use case rather than an unclear work-around.!
when you initialize it then set it later: It works, but I don't want to shup the compiler just because why not, I want an attribute that shows my intentions clear.Also, can anyone come up with a better name for this attribute?
Beta Was this translation helpful? Give feedback.
All reactions