If lazy initialization is a common case, that seems likely to require differing property types, as the backing field would often be nullable, but the initialized field would be not nullable.
Is it not possible for the compiler to simply ignore the warning when it generates the field?
public Foo LazyInstance => field ??= new Foo(42); // just don't report an initialization warning 4head
we probably need to find what scenarios are served by that design
There's also a scenario in Blazor where you need to call a base method if you have some data changing outside of an event:
public ModelType Model { get; set { field = value; StateHasChanged(); // forgetting this call will not re-render the component so the change won't be visible } }
Sure, it's similar to the INPC example, but it's also proof that another case is out there.
Additionally, can get => field;
be simplified to get;
when field
is already in use in the setter? It's a bit minor, but may be worth considering.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4