Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 428349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:40:01+00:00 2026-05-12T19:40:01+00:00

I have a class with an event: public event MyEventHandler MyEvent; Is there any

  • 0

I have a class with an event:

public event MyEventHandler MyEvent;

Is there any way of getting a handle to the collection of objects (by reflection or otherwise) that are listening to this event?

EDIT – Um, sorry to move the goalposts – I need to be able to do this using reflection bc I have a string value representing the event name, and I need to find the listeners. I can’t see an obvious way of accessing the GetInvocationList property using reflection…

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T19:40:02+00:00Added an answer on May 12, 2026 at 7:40 pm
    List<object> targets = MyEvent.GetInvocationList().Select(d => d.Target).ToList();
    

    Doing this via reflection will be somewhat obfuscated, if even possible, unfortunately, because this syntax:

    public event EventHandler MyEvent;
    

    …

    MyEvent(this, EventArgs.Empty);
    

    Is syntactic sugar. What this actually does is:

    private EventHandler compilerGeneratedName;
    
    public event EventHandler MyEvent
    {
        add { compilerGeneratedName += value; }
        remove { compilerGeneratedName -= value; }
    }
    

    …

    compilerGeneratedName(this, EventArgs.Empty);
    

    In other words, events have always had the declarative shorthand that properties only recently received. As a result, in order to get at the invocation list you’ll have to inspect the private variable, which is named by the compiler (unless, of course, you use the longhand syntax yourself and know the name of the instance variable).

    There is no direct way to associate an externally exposed event construct with a backing handler any more than there is a direct way to tie a property to a backing variable: namely because there isn’t necessarily a one-to-one relationship. Very likely there is, but as a rule it doesn’t have to be that way.

    You can try using reflection to inspect the private variables that are of the proper EventHandler<> type on the type that declares the event (note that you’ll have to do it at the specific type that declares the event, not on a subclass) and see if you can determine some sort of correlation with the names, but this will be an unreliable solution at best.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Any efficient/reliable way to expose one event? I have a class, MultipleDocumentCopier that copies
I have a class essentially: public class WindowEvent extends Event { public static const
I have this code : class Event{}; class CustomEvent:public Event{}; class Handler { public:
Let's say I have defined the following class: public abstract class Event { public
I have model: [XmlRoot(ElementName = event, IsNullable=true)] public class Event { public int id
I have an Event class. Due to the way dates are handled, we need
I have created this datastructure: class Event { public: Event(EVENT_TYPE type, void* pSender =
Let's say we have the following piece of code: public class Event { }
I have a custom event class public class FFTDrawEvent extends Event { public static
Why would a 'public event EventHandler cccc' be null? I have a class that's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.