Replies: 6 comments
-
Why would this be preferable to auto-implemented properties? public bool IsEditing { get; private set; } |
Beta Was this translation helpful? Give feedback.
-
I think this feature is useless as we can write or use a tool to complete the property defination,and ofcourse,without the tools,it's also easy to do in VS2017.(With Ctrl+.) |
Beta Was this translation helpful? Give feedback.
-
Because sometimes we have thins like NotifyPropertyChanged inside the setters in the ViewModels:
So you cannot relay on the auto-implemented properties:
|
Beta Was this translation helpful? Give feedback.
-
C# is not the kind of language that will infer the existence of a field or local based on usage. Declaration is necessary. There are proposals to allow for either scoped backing fields: public bool IsEditing {
// field is scoped within the property only
bool _isEditing;
get => _isEditing;
set => RaisePropertyChanged(ref _isEditing, value);
} Or proposals to allow for an inferred backing field: // field is a contextual keyword just like value
public bool IsEditing {
get => field;
set => RaisePropertyChanged(ref field, value);
} |
Beta Was this translation helpful? Give feedback.
-
That last option would be just fine in most of scenarios |
Beta Was this translation helpful? Give feedback.
-
Yes, see #140 which I want really bad. Even further, we should be able to do: // field is a contextual keyword just like value
public bool IsEditing { get; set => RaisePropertyChanged(ref field, value); } |
Beta Was this translation helpful? Give feedback.
-
Currently we have to write a backing variable for the property:
private bool _isEditing; public bool IsEditing { get => _isEditing; }
I think the _isEditing variable can be inferred by the compiler as it is being stated in the getter so the resulting code would be like:
public bool IsEditing { get => _isEditing; }
Sometimes the viewmodels have dozens of properties like this so it'll help make it much more readable, specially if we have long variable names.
Beta Was this translation helpful? Give feedback.
All reactions