Allow ??= operator on auto-properties #3458
Replies: 5 comments
-
This is superseded by #140, which will allow you to write public ICommand DoSomethingCommand => field ??= new Command(this.DoSomething); |
Beta Was this translation helpful? Give feedback.
-
Seems like another use-case for #140 public List<Thing> Things => field ??= new List<Thing>(); |
Beta Was this translation helpful? Give feedback.
-
@Joe4evr It is not approved, is it? |
Beta Was this translation helpful? Give feedback.
-
It's championed, discussed in LDM last month, and I think it was @jnm2 who did a lot of work for the feature already. |
Beta Was this translation helpful? Give feedback.
-
Another one to add to https://gist.github.com/jnm2/d3b37a43894f1738273005e69824d089#140-mentioned-as-preferred-or-alleviating-the-pain @Joe4evr I just started the prototype a few days ago and it looks like it will go relatively quickly |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Allow ??= operator on auto-properties
Summary
The ??= currently is a shorthand for:
Motivation
Currently "lazy" properties take up too much space and require too much typing for something that should be able to be expressed more easily.
Detailed design
Allow ??= on properties. So that these two mean the same thing:
Drawbacks
People who don't know what
??=
does might be confused.Unresolved questions
Should the backing field generated be accessible by other members of the class? If so, how? Like
DoSomethingCommand.field
,fieldof(DoSomethingCommand)
or not at all?Beta Was this translation helpful? Give feedback.
All reactions