473,407 Members | 2,676 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,407 software developers and data experts.

Event Invocation List

I'm trying to serialize my menubar for use later, however I want to use
XML to serialize this list. Not a problem with the Text property of the
MenuItem control, however the ClickEvent is a bit trickier. I managed
to find some code in the MSDN on getting a class method (and therefore
a delegate) using a string, making deserialization possibe, however
turning an event's evocation list into a string/array of strings
doesn't seem as easy. I'd have to get the invocation list of the event,
and from the looks of it's not possible (compiler gives an error: The
event can only appear on the left hand side of += or -=). Anyone have
any ideas?

Thanks in advance

-Rob

Feb 28 '06 #1
3 8656
For the invocation list .... MyEvent.GetInvocationList()
Here is a sample is taken from
[http://msdn.microsoft.com/msdnmag/is...ventHandling/]

' From FileSearch4.vb
Dim ListenerList() As System.Delegate
Dim Listener As FileFoundEventHandler
ListenerList = FileFoundEvent.GetInvocationList()

' Search for matching file names.
Dim afi() As FileInfo = diLocal.GetFiles(Me.FileSpec)

For Each fi As FileInfo In afi
For Each Listener In ListenerList
Try
Listener.Invoke(fi)
Catch
' Something goes wrong? Just move on to
' the next event handler.
End Try
Next
alFiles.AddRange(afi)
Next

I hope that is helpful.

Sincerely,
Bobby

Feb 28 '06 #2
I was hoping to get the invocation list of an existing instance, after
the existing idiom:

swfObjectInstance.SomeEvent += new EventHandler(MyMethod);

then elsewhere:

Delegate[] invocationList =
swfObjectInstance.SomeEvent.GetInvocationList();

But this raises an error of CS0079.

Well.. I did a bit more research and it doesn't seem possible unless I:

1) Do what you've shown here, by creating my own EventHandler and
passing that on to the object
2) Deriving the class and handling it internally

If anyone has any alternatives, I'll be glad to hear them.

-Rob

Feb 28 '06 #3
robinhoode <ro********@gmail.com> wrote:
I was hoping to get the invocation list of an existing instance, after
the existing idiom:

swfObjectInstance.SomeEvent += new EventHandler(MyMethod);

then elsewhere:

Delegate[] invocationList =
swfObjectInstance.SomeEvent.GetInvocationList();

But this raises an error of CS0079.

Well.. I did a bit more research and it doesn't seem possible unless I:

1) Do what you've shown here, by creating my own EventHandler and
passing that on to the object
2) Deriving the class and handling it internally

If anyone has any alternatives, I'll be glad to hear them.


No - the point of the encapsulation of an event is that all you can do
is subscribe and unsubscribe. You don't get to manipulate the list in
any other way, unless the owner chooses to expose the delegate to you
in another way.

For field-like events you *could* use reflection to get the delegate,
but not all events are declared in a field-like way (i.e. they're not
all backed by a field of the same name).

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 28 '06 #4

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

Similar topics

3
by: Guadala Harry | last post by:
In the following line of code, what is the point of including the 'new' keyword? List.Changed -= new ChangedEventHandler(ListChanged); I'm just a bit confused because I thought 'new' was used...
1
by: Fei Li | last post by:
I do not know if event handlers are called by the sequence of the subsription sequence.
1
by: David Chelimsky | last post by:
I'd like to access a list of the delegates attached to an Event on a Control. I know how to get it from a custom event and delegate - using GetInvocationList() from the Event - but I can't get a...
5
by: Charles Law | last post by:
I think I asked the wrong question last time, so I am starting a separate post to distinguish them. Take five classes: ClassA and ClassW...Z ClassA raises five events: Event1...5 ClassW...Z...
13
by: Charles Law | last post by:
Mr "yEaH rIgHt" posted the following link about a week ago in answer to my question about removing event handlers. > http://www.vbinfozine.com/t_bindevt.shtml Following on from that post, the...
3
by: Beth | last post by:
in the following: this.ExitButton.Click += new System.EventHandler(this.ExitButton_Click); if I saw an equation, such as y +=x; then y = y+x. But what is the meaning in the event handler. I...
6
by: Peter M. | last post by:
Hi all, If an event has multiple subscribers, is it possible to cancel the invocation of event handlers from an event handler? Or to be more specific: I'm subscribing to the ColumnChanging...
1
by: Peter Rilling | last post by:
How can I get access to the invocation list for a multicast delegate (i.e. an event) at runtime? Suppose that I have a reference to a class that has an event. I would like to be able to...
6
by: Sharon | last post by:
When an object is register to event (delegate marked as event) with one of its methods, what happen when the event is raised if the object is dead (finalized)? In this case the delegate invocation...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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
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
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...
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.