[Request] Replace focus on semi-auto-properties with focus on property-scoped fields #6632
Unanswered
RenderMichael
asked this question in
General
Replies: 2 comments 2 replies
-
Just found that this proposal has an associated issue #133 |
Beta Was this translation helpful? Give feedback.
2 replies
-
#140 is still a good initial focus because of how much less code it is for many more scenarios. I agree with this lazy value type pain and am hoping #133 happens soon afterwards since #140 doesn't improve that situation. Most of the time, properties like this don't have setters. This is what I would prefer: // One-liner. #140
public string ReferenceTypeMember => field ??= CalculateStringValue();
// One-liner with a manually-declared field. #133
public int ValueTypeMember { int? field; get => field ??= CalculateIntValue(); } |
Beta Was this translation helpful? Give feedback.
0 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.
Uh oh!
There was an error while loading. Please reload this page.
-
There was a lot of talk for C#11 about semi-auto-properties, but it was scrapped for 11.
I want to propose instead focusing on property-scoped fields. They would work like:
I am really interested in the functionality of semi-auto-properties, but this proposal would cover 100% of s-a-p scenarios, and add additional useful functionality.
For example, the nullability of the backing field, For reference types with NRT enabled, it would be iffy to make the backing field nullable where the property type isn't. For value types, that's a definite no-go.
Beta Was this translation helpful? Give feedback.
All reactions