I understand that one can raise an event in the class that the implementation declaration occurs, but I wish to raise the event at the base class level and have the derived class's event be raised:
public interface IFoo
{
event EventHandler<FooEventArgs> FooValueChanged;
void RaiseFooValueChanged(IFooView sender, FooEventArgs e);
}
[TypeDescriptionProvider(typeof(FooBaseImplementor))]
public abstract class FooBase : Control, IFoo
{
public virtual event EventHandler<FooEventArgs> FooValueChanged;
public void RaiseFooValueChanged(IFooView sender, FooEventArgs e)
{
FooValueChanged(sender, e);
}
}
I cannot have the FooValueChanged event abstract, because then the base class cannot raise the event. Current the code runs, but the call FooValueChanged(sender, e) throws a NullReferenceException because it doesn't call the derived class's event, only that of the base class.
Where am I going wrong?
I can have the event and the raiser both abstract, but then I need to remember to call FooValueChanged(sender, e) in every single derived class. I'm trying to avoid this while being able to use the Visual Studio designer for derived controls.