explicit interface implementation does not work with events

  • Thread starter Thread starter cody
  • Start date Start date
C

cody

it seems to me that explicit interface implementation does not work with
events:

class Foo : IContentchangeableControl
{
event EventHandler MyNs.IContentchangeableControl.ContentChanged;
}

yields to CS0071 and CS1519.
 
For some reason you need to perform explicit registration in this case (I can't see why particularly)

using System;

class App
{
static void Main(string[] args)
{
Bar b = new Bar();
IFoo f = b;
f.Foo +=new EventHandler(f_Foo);
b.Go();
}

private static void f_Foo(object sender, EventArgs e)
{
Console.WriteLine("TADA!");
}
}

class Bar : IFoo
{
// this stores the underlying delegate
EventHandler foo;
event EventHandler IFoo.Foo
{
// provide explicitly the register/unregister functions
add{ foo += value; }
remove{ foo -= value; }
}
public void Go()
{
// fire the underlying delegate
foo(this, EventArgs.Empty);
}

}

interface IFoo
{
event EventHandler Foo;
}

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

it seems to me that explicit interface implementation does not work with
events:

class Foo : IContentchangeableControl
{
event EventHandler MyNs.IContentchangeableControl.ContentChanged;
}

yields to CS0071 and CS1519.
 
Back
Top