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 3999332
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:38:38+00:00 2026-05-20T07:38:38+00:00

From this MSDN article , there’s quite a few ways to hook up a

  • 0

From this MSDN article, there’s quite a few ways to hook up a delegate using reflection.

It seems the best way is with the CreateDelegate method:

Delegate d = Delegate.CreateDelegate(delegateType, targetObject, handlerMethodName);

Under normal circumstances, I’d be pointing to the handler method that is within the targetObject class.
But what if the delegate was created anonymously? Example:

public delegate void SelectedVehiclesCollectionDelegate(string query, List<Vehicles> list);
...
myObject.SelectedVehiclesCollection = (query, list) =>
                    {
                      //assign list of vehicles to list matching query
                    };  

There’s not a method within the class definition to which the delegate is referencing. I need to invoke this delegate which is unknown at runtime, obtaining the list of items are a result.

Ok, looks like my terminology got the best of me. Wasnt aiming at creating a handler but invoke what’s already there (Tomas Petricek’s answer still gives me some good insight though).

  • 1 1 Answer
  • 1 View
  • 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-20T07:38:39+00:00Added an answer on May 20, 2026 at 7:38 am

    Given your comment, it sounds like this is about calling a delegate rather than creating one, in which case Delegate.DynamicInvoke is probably what you’re after, if you really don’t know the relevant delegate type at compile time.

    If you do know the relevant delegate type, just not the property name, you can cast:

    MyDelegate handler = (MyDelegate) propertyInfo.GetValue(obj, null);
    handler(...); // Call as normal
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I copy-pasted from MSDN this code: using System.Security.Cryptography; byte[] buffer = enc.GetBytes(text); SHA1CryptoServiceProvider cryptoTransformSHA1
This is a XAML code sample taken from the MSDN library article for the
The following saying is quoted from this article in MSDN. ... strong-name signing makes
I was reading this article from MSDN on Dependency Injection and I saw a
Why in this example from MSDN, in GetEnumerator method, PeopleEnum returns IEnumerator ? public
I picked up this code from a msdn blog : #include <windows.h> #include <stdio.h>
This is an example xml from MSDN <?xml version=1.0?> <!-- A fragment of a
I've tried this example directly from MSDN: Dim Screens() As System.Windows.Forms.Screens and I can't
So, this example comes right from MSDN. http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.readelementcontentasbase64.aspx Pretty much the only thing I
Given this MSDN article, we learn that the Common Type System in .Net has

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.