Replies: 7 comments
-
I'd much rather see what has been suggested already (#140), the bool IsDirty { get; set => field = MyMethod(value); } = false; |
Beta Was this translation helpful? Give feedback.
-
Should be fine, although one loses this in-line capability e.g.: |
Beta Was this translation helpful? Give feedback.
-
That's quite useful, but when you have a readonly property my bet is on property-scoped fields, object Foo { object field; get => field ??= Compute(); } |
Beta Was this translation helpful? Give feedback.
-
OK, I now realized I missed the meaning of the <> keyword. It represents the <>. Thanks for making that clear. If the implementation can also allow multiple in-line statements , that would satisfy my requirement. I simply want to trigger actions when <>ing without having to code the complete property. Maybe a better example based on the <> keyword approach would be: |
Beta Was this translation helpful? Give feedback.
-
```c#
// Syntax-highlighted block
object Foo { get => field ??= Compute(); set => {field = value; FireCustomAction(value);} } = false;
``` Gives // Syntax-highlighted block
object Foo { get => field ??= Compute(); set => {field = value; FireCustomAction(value);} } = false; |
Beta Was this translation helpful? Give feedback.
-
I do really want to see #140. It'll cover so many of the motivations in these asks. |
Beta Was this translation helpful? Give feedback.
-
Using a backing field without naming it was considered in https://github.com/dotnet/csharplang/blob/master/meetings/2020/LDM-2020-04-01.md |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
This is probably not a new suggestion, but other than just allowing
e.g. bool IsDirty {get; set;} = false;
Please consider allowing us to add code to them without losing the advantage of anonymous backing fields...
e.g. bool IsDirty {get; set (value) => { MyMethod(value)};} = false;
We can now trigger events if properties change, without having to code with backing fields. This cleans up
Beta Was this translation helpful? Give feedback.
All reactions