We have a class ModelBase
that has defined a PropertyChangedEventHandler PropertyChanged
. Then we inherit from this class, and using kind of a decorator pattern, add more functionality to it -- filtering, inserting, etc. We wrap the current object into another one each time we add stuff to it and copy all the properties so we can use them in the next class.
public class ModelBase<T> : IModel<T> where T : IView, new()
{
...
...
public event PropertyChangedEventHandler PropertyChanged;
protected internal void RaisePropertyChanged(string propertyName)
{
if(PropertyChanged != null)
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
public class ViewModel : ModelBase<Grid>, IViewModel
{
protected internal ViewModel(iewModel viewModel)
: base(viewModel)
{
// Copy all the properties of viewModel to the ones of this instance
...
...
PropertyChanged = viewModel.PropertyChanged;
}
}
The issue is that when trying copy the PropertyChanged
event handler the compiler throws the error ... can only appear on the left hand side of += or -= operator...
.
Is there a way how a can copy PropertyChanged
property to the next decorator isntance?