-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: Null-conditional Assignment (Lazy Initialization Operator) #5163
Comments
Dupe of #3366. |
@HaloFour Sorry I didn't see it, since it's closed. They didn't mention |
Well there is #3630 specifically for lazy initialization using a decorator on property signatures. Using the operator syntax makes it feel like it is much more general purpose. The fact that it could be used to emulate lazy behaviors in properties I don't think matters much, and if it would behave differently than a null assignment in that context I think that would make it confusing. |
@HaloFour Lazy initialization is not bounded to properties. you still want to use it in other places. what about initializing a private field in some method? It is general purpose. you can use them everywhere for initializing members. and it just works — thread safely. |
This is neatly covered by replace/original feature. public class Foo {
[Lazy]
public object Value => GetValue();
}
partial class Foo {
object mValue;
replace object Value => mValue ?? (mValue = original);
} Thread safety and other stuff is up to the code gen provider. |
Currenty (no concurrency check):
Null-conditional Assignment:
This can be implemented in a way that properly use the
System.Threading.LazyInitializer
class.The text was updated successfully, but these errors were encountered: