My code has very many of these constructs:
ParamViewModel[] _btns;
public ParamViewModel[] Btns
{
get => _btns;
set => SetProperty(ref _btns, value);
}
Is there any way to do this with a generic to enable me to cut down of the lines of code as they are all the same but with just a different data type, string, int, Color etc.
For reference here's what SetProperty does:
public class ObservableObject : INotifyPropertyChanged
{
protected virtual bool SetProperty<T>(
ref T backingStore, T value,
[CallerMemberName]string propertyName = "",
Action onChanged = null)
{
if (EqualityComparer<T>.Default.Equals(backingStore, value))
return false;
backingStore = value;
onChanged?.Invoke();
OnPropertyChanged(propertyName);
return true;
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName]string propertyName = "") =>
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}