Yes you can implement that on your generic class as it simply defines an event that must be implemented:
public class MyClass<T> : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
}
The delegate for that property doesn't demand anything more special than the property name and an instance reference to the object raising the event, there is no generics magic required for it.
Your consuming class can simply hook into it:
var instanceOfMyClass = new MyClass<SomeObject>();
instanceOfMyClass.PropertyChanged += theHandlerForTheEvent;
...or...
instanceOfMyClass.PropertyChanged += (o, e) => { do something; };
What you appear to be doing actually makes a very good pattern when GridObjectDataSource<T>
is used as an abstract base class and derived classes (viewmodels etc.) specify the actual type of T
:
public abstract class GridObjectDataSource<T> : INotifyPropertyChanged
{
public abstract void DoSomething(T someInput);
protected virtual void OnPropertyChanged(string propertyName)
{
var handler = PropertyChanged;
if (handler != null)
handler(this, new PropertyChangedEventArgs(propertyName));
}
public event PropertyChangedEventHandler PropertyChanged;
}
public class MySpecificViewModel : GridObjectDataSource<int>
{
public override void DoSomething(int someInput)
{
}
}