473,769 Members | 2,134 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

explicit interface implementation does not work with events

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

class Foo : IContentchangea bleControl
{
event EventHandler MyNs.IContentch angeableControl .ContentChanged ;
}

yields to CS0071 and CS1519.
Nov 17 '05 #1
2 1606
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.WriteLi ne("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 : IContentchangea bleControl
{
event EventHandler MyNs.IContentch angeableControl .ContentChanged ;
}

yields to CS0071 and CS1519.

Nov 17 '05 #2
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.WriteLi ne("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 : IContentchangea bleControl
{
event EventHandler MyNs.IContentch angeableControl .ContentChanged ;
}

yields to CS0071 and CS1519.

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
2806
by: Steve W. | last post by:
I just read the section (and did the exercise) in the C# Step by Step book that covers Explict Interface Implementation (where you specify in the method implementation the specific interface that you are implementing in the class. Other than to resolve the problem that arises when a class implements two interfaces with the same method signature, what good is it?
0
243
by: cody | last post by:
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.
2
2514
by: COLIN JACK | last post by:
Hi All, I've got a situation where I'm implementing an interface (BaseInterface in example below) and I want to use explicity interface implementation of an event so that I can add type safety. To see what I mean look at the example below where the class implementing the interface actually wants the event to be for a more specific delegate. Now this seems to work but the code, to me is unnecessarily ugly. This leaves me wondering if...
0
2221
by: Ken | last post by:
Hi I have a little application that does datavalidation. It supports dynamically loaded plugins (you drop a dll with a class implementing IValidator<Tin the same dir as the main application). All classes that implement this interface are shown in a drop down in a DataGridViewComboBoxColumn named Validator. By choosing the class to validate this specific data in the drop downbox IValidator<T>.Validate is called and returns true/false....
1
9997
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8873
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3965
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3565
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.