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

  • SEARCH
  • Home
  • 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 1095435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:07:26+00:00 2026-05-17T00:07:26+00:00

I need to get all events from the current class, and find out the

  • 0

I need to get all events from the current class, and find out the methods that subscribe to it. Here I got some answers on how to do that, but I don’t know how I can get the delegate when all I have is the EventInfo.

var events = GetType().GetEvents();

foreach (var e in events)
{
    Delegate d = e./*GetDelegateFromThisEventInfo()*/;
    var methods = d.GetInvocationList();
}

Is it possible to get a delegate with the EventInfo? How?

  • 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-17T00:07:26+00:00Added an answer on May 17, 2026 at 12:07 am

    The statement var events = GetType().GetEvents(); gets you a list of EventInfo objects associated with the current type, not the current instance per se. So the EventInfo object doesn’t contain information about the current instance and hence it doesn’t know about the wired-up delegates.

    To get the info you want you need to get the backing field for the event handler on your current instance. Here’s how:

    public class MyClass
    {
        public event EventHandler MyEvent;
    
        public IEnumerable<MethodInfo> GetSubscribedMethods()
        {
            Func<EventInfo, FieldInfo> ei2fi =
                ei => this.GetType().GetField(ei.Name,
                    BindingFlags.NonPublic |
                    BindingFlags.Instance |
                    BindingFlags.GetField);
    
            return from eventInfo in this.GetType().GetEvents()
                   let eventFieldInfo = ei2fi(eventInfo)
                   let eventFieldValue =
                       (System.Delegate)eventFieldInfo.GetValue(this)
                   from subscribedDelegate in eventFieldValue.GetInvocationList()
                   select subscribedDelegate.Method;
        }
    }
    

    So now your calling code can look like this:

    class GetSubscribedMethodsExample
    {
        public static void Execute()
        {
            var instance = new MyClass();
            instance.MyEvent += new EventHandler(MyHandler);
            instance.MyEvent += (s, e) => { };
    
            instance.GetSubscribedMethods()
                .Run(h => Console.WriteLine(h.Name));
        }
    
        static void MyHandler(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }
    }
    

    The output from the above is:

    MyHandler
    <Execute>b__0
    

    I’m sure you can jig around with the code if you wish to return the delegate rather than the method info, etc.

    I hope this helps.

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

Sidebar

Related Questions

We need to get all the instances of objects that implement a given interface
I need to get all substrings from string. For ex: StringParser.GetSubstrings([start]aaaaaa[end] wwwww [start]cccccc[end], [start],
In C# i need to get all values of a particular property from an
I'm trying to figure out how to get the current space # from mission
I am currently trying to get all events from a facebook page using OpenGraph.
I need get all items these have no categories int? categoryId = null; var
I need to get all dlls in my application root directory. What is the
I need to get all the objects whose id matches a specific pattern .
I need to get all controls inside a specific RowDefinition/ColumnDefinition without iterating through all
I need to get all characters between '(' and ')' chars. var str =

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.