Re: explicit interface implementation does not work with events
- From: "Richard Blewett [DevelopMentor]" <richardb@xxxxxxxxxxxxxxxxx>
- Date: Wed, 20 Apr 2005 04:14:17 -0700
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.
.
- References:
- Prev by Date: Re: Referring to controls via loops - comments and suggestions
- Next by Date: Transform?
- Previous by thread: explicit interface implementation does not work with events
- Next by thread: Transform?
- Index(es):
Relevant Pages
|