Replies: 5 comments 8 replies
-
I like that you switched priorities about Im also curious how parametreless constructors will flesh out in the end considering legacy baggage |
Beta Was this translation helpful? Give feedback.
-
IMO, I think this problem can be solved by allowing the property-scoped fields to access public class C {
public string Foo {
Lazy<string> lazy = new Lazy<string>(this.CalculateFoo);
get => lazy.Value;
}
private string CalculateFoo() { /* expensive stuff here */ }
} would translate into: public class C {
Lazy<string> $Unspeakable_Foo_lazy;
public C() : base() {
$Unspeakable_Foo_lazy = new Lazy<string>(this.CalculateFoo);
}
public string Foo {
get => $Unspeakable_Foo_lazy.Value;
}
private string CalculateFoo() { /* expensive stuff here */ }
} Even better would be if the property-scoped field could be treated like a static local and support inference: public string Foo {
var lazy = new Lazy<string>(this.CalculateFoo);
get => lazy.Value;
} Although even without that. with target-typed |
Beta Was this translation helpful? Give feedback.
-
Are you really sure that introducing non-defaultable struct later won't cause more pain? If so, the decision should be OK. |
Beta Was this translation helpful? Give feedback.
-
I'm not sure that |
Beta Was this translation helpful? Give feedback.
-
Why not simply warn on private and internal parameterless constructors in a struct, rather than at the use site? |
Beta Was this translation helpful? Give feedback.
-
https://github.com/dotnet/csharplang/blob/master/meetings/2021/LDM-2021-03-10.md
Agenda
field
keywordBeta Was this translation helpful? Give feedback.
All reactions