Hi,
when I run the following code:
using System;
namespace ConsoleApplication22
{
class Program
{
static void Main(string[] args)
{
BaseClass baseClass = new BaseClass();
BaseClass inheritedBaseClass = new InheritedClass();
InheritedClass inheritedClass = new InheritedClass();
baseClass.EventA += new EventHandler(baseClass_EventA);
inheritedBaseClass.EventA += new
EventHandler(inheritedBaseClass_EventA);
inheritedClass.EventA += new
EventHandler(inheritedClass_EventA);
Console.ReadLine();
}
static void inheritedClass_EventA(object sender, EventArgs e)
{
throw new Exception("The method or operation is not
implemented.");
}
static void inheritedBaseClass_EventA(object sender, EventArgs
e)
{
throw new Exception("The method or operation is not
implemented.");
}
static void baseClass_EventA(object sender, EventArgs e)
{
throw new Exception("The method or operation is not
implemented.");
}
}
class BaseClass
{
public virtual event EventHandler EventA
{
add
{
this.EventB += this.BaseClass_EventB;
this.EventC += this.BaseClass_EventC;
}
remove
{
this.EventC -= this.BaseClass_EventC;
this.EventB -= this.BaseClass_EventB;
}
}
public virtual event EventHandler EventB;
public virtual event EventHandler EventC
{
add
{
}
remove
{
}
}
void BaseClass_EventC(object sender, EventArgs e)
{
throw new Exception("The method or operation is not
implemented.");
}
void BaseClass_EventB(object sender, EventArgs e)
{
throw new Exception("The method or operation is not
implemented.");
}
}
class InheritedClass : BaseClass
{
public override event EventHandler EventB
{
add
{
Console.WriteLine("EventB: Override add called");
}
remove
{
Console.WriteLine("EventB: Override remove called");
}
}
public override event EventHandler EventC
{
add
{
Console.WriteLine("EventC: Override add called");
}
remove
{
Console.WriteLine("EventC: Override remove called");
}
}
}
}
Then only the override of EventC will be called, not the one from
EventB. Was this to be expected?
Thx Karsten