Good day,

I`ve encountered a slight annoyance which, although it can easily be bypassed, I would much rather dispose of altogether.

Take the following two classes:

Code:
    class BaseClass
    {
        public event EventHandler BaseEvent;
        protected virtual event EventHandler VirtualEvent;

        void SomeBaseMethod()
        {
            this.BaseEvent(this, EventArgs.Empty);
        }
    }

    class DerivedClass : BaseClass
    {
        protected override event EventHandler VirtualEvent;

        void SomeDerivedMethod()
        {
            this.VirtualEvent(this, EventArgs.Empty);
            this.BaseEvent(this, EventArgs.Empty);
        }
    }
The above code shows two ways I tried using to the effect of generating a base-class event from a derived class.
Both ways yielded problems:

  1. VirtualEvent :
    It seems that generating an overridden event does not cause the base event to be raised, but a different one altogether. At least, that is how it seems, since I had registered methods to the base event, but upon raising of the derived event, a NullReferenceException was thrown, which indicates that no handlers were ever assigned to the raised event.
  2. BaseEvent :
    This method does not even pass compilation.
    C# enforces the 'event' access modifier even with inheriting classes, so that the event itself can only be initiated from context of the base class.
    The only thing that can be done from within the context of a derived class is registration-type calls (using the '+=' and '-=' operators).


The bypassing I have mentioned earlier involves creating a Protected method in the base class with argument types that coninside with the event arguments, and whose sole purpose is to raise teh event.
In other words, something like:
base.RaiseBaseEvent(senderArgument, eventArgsArgument);

I would much appreciate it if anyone could point out a better way to accomplish the goal I have described here.

Thanks in advance.