473,396 Members | 1,758 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to reference an event ?

I have declared an interface containing an event.

The class implementing the interface should implement the event by
referring to an event on an object owns, instead of implementing the
event, but this does not seem to be possible, because I get the
compiler error:

The event 'SelectionChanged' can only appear on the left hand side of
+= or -=.

Example:

interface I
{
event MyEventHandler EventName;
}

public class C1
{
public event MyEventHandler EventName;
}

public class C2 : I
{
private C1 c1;

public event MyEventHandler EventName = c1.EventName;

}

How can the above functionality be achieved. I need this functionality
because I am implementing the Model View Presenter pattern as described
on Martin Fowlers webpage, and here it is suggested to use an interface
of the view, to make unit testing of the GUI behaviour possible.

Regards Stig Nielsson

Nov 17 '05 #1
3 2028
"The class implementing the interface should implement the event by
referring to an event on an object owns"

afaik event cannot be implemented, it can be called ( in the class that owns
it ) or subscribed to it by the class that has the object with the event.

--
Vadym Stetsyak aka Vadmyst

"Stig" <st****@gmail.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
I have declared an interface containing an event.

The class implementing the interface should implement the event by
referring to an event on an object owns, instead of implementing the
event, but this does not seem to be possible, because I get the
compiler error:

The event 'SelectionChanged' can only appear on the left hand side of
+= or -=.

Example:

interface I
{
event MyEventHandler EventName;
}

public class C1
{
public event MyEventHandler EventName;
}

public class C2 : I
{
private C1 c1;

public event MyEventHandler EventName = c1.EventName;

}

How can the above functionality be achieved. I need this functionality
because I am implementing the Model View Presenter pattern as described
on Martin Fowlers webpage, and here it is suggested to use an interface
of the view, to make unit testing of the GUI behaviour possible.

Regards Stig Nielsson

Nov 17 '05 #2
Hi,

You need to do nothing in the class, think of it as if the event was
declared in the class, you can use it without making any further reference
to it.

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Stig" <st****@gmail.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
I have declared an interface containing an event.

The class implementing the interface should implement the event by
referring to an event on an object owns, instead of implementing the
event, but this does not seem to be possible, because I get the
compiler error:

The event 'SelectionChanged' can only appear on the left hand side of
+= or -=.

Example:

interface I
{
event MyEventHandler EventName;
}

public class C1
{
public event MyEventHandler EventName;
}

public class C2 : I
{
private C1 c1;

public event MyEventHandler EventName = c1.EventName;

}

How can the above functionality be achieved. I need this functionality
because I am implementing the Model View Presenter pattern as described
on Martin Fowlers webpage, and here it is suggested to use an interface
of the view, to make unit testing of the GUI behaviour possible.

Regards Stig Nielsson

Nov 17 '05 #3
Stig <st****@gmail.com> wrote:
I have declared an interface containing an event.

The class implementing the interface should implement the event by
referring to an event on an object owns, instead of implementing the
event, but this does not seem to be possible, because I get the
compiler error:

The event 'SelectionChanged' can only appear on the left hand side of
+= or -=.

Example:

interface I
{
event MyEventHandler EventName;
}

public class C1
{
public event MyEventHandler EventName;
}

public class C2 : I
{
private C1 c1;

public event MyEventHandler EventName = c1.EventName;

}

How can the above functionality be achieved. I need this functionality
because I am implementing the Model View Presenter pattern as described
on Martin Fowlers webpage, and here it is suggested to use an interface
of the view, to make unit testing of the GUI behaviour possible.


You can't do that, as events are basically sets of methods (add, remove
and potentially raise, although C# doesn't support the last).

In C2, you could implement the event as:

public event MyEventHandler EventName
{
add
{
c1.EventName += value;
}
remove
{
c1.EventName -= value;
}
}

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #4

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

Similar topics

4
by: Todd | last post by:
Is it possible to pass an argument by reference through an event in C++ managed code? For example, can I do the following? public __gc class MyClass : public Control { public: __event...
6
by: trexim | last post by:
Hi, I am trying to create a Web Reference for CSTA using the URL http://www.ecma-international.org/standards/ecma-348/csta-wsdl/csta-wsdl-all-operations.wsdl Visual .Net complains that: "...
2
by: Todd | last post by:
Is it possible to pass an argument by reference through an event in C++ managed code? For example, can I do the following? public __gc class MyClass : public Control { public: __event...
14
by: Steve Teeples | last post by:
I don't understand why I cannot use a property to modify data within a struct. Can someone tell me why I get the error "Cannot modify the return value of "myData.TheData" because it is not a...
1
by: vishnu | last post by:
Hi, I am working on asp.net project which I converted the code fron VB to C# and instead of RaiseEvent in VB code I used the following code. using System; using System.Data; using...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.