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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:01:22+00:00 2026-05-13T17:01:22+00:00

How can I determine if a MethodInfo fits a distinct Delegate Type? bool IsMyDelegate(MethodInfo

  • 0

How can I determine if a MethodInfo fits a distinct Delegate Type?

bool IsMyDelegate(MethodInfo method);

Edit:
I’m given a MethodInfo object and want to know if it fits the delegate interface.
Apart from the obvious

    private bool IsValidationDelegate(MethodInfo method)
    {
        var result = false;
        var parameters = method.GetParameters();
        if (parameters.Length == 2 &&
            parameters[0].ParameterType == typeof(MyObject1) &&
            parameters[1].ParameterType == typeof(MyObject2) &&
            method.ReturnType == typeof(bool))
        {
            result = true;
        }
        else
        {
            m_Log.Error("Validator:IsValidationDelegate", "Method [...] is not a ValidationDelegate.");
        }
        return result;
    }
  • 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-13T17:01:22+00:00Added an answer on May 13, 2026 at 5:01 pm

    If method is a static method:

    bool isMyDelegate =
      (Delegate.CreateDelegate(typeof(MyDelegate), method, false) != null);
    

    If method is an instance method:

    bool isMyDelegate =
      (Delegate.CreateDelegate(typeof(MyDelegate), someObj, method, false) != null)
    

    (Unfortunately you need an instance in this case because Delegate.CreateDelegate is going to try to bind a delegate instance, even though in this case all we care about it whether the delegate could be created or not.)

    In both cases, the trick is basically to ask .NET to create a delegate of the desired type from the MethodInfo, but to return null rather than throwing an exception if the method has the wrong signature. Then testing against null tells us whether the delegate had the right signature or not.

    Note that because this actually tries to create the delegate it will also handle all the delegate variance rules for you (e.g. when the method return type is compatible but not exactly the same as the delegate return type).

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

Sidebar

Related Questions

I am looping through an NSMutableArray and want to know how I can determine
Given a Hibernate domain object, is there some way I can determine if it
Can somebody please let me know how we can determine if a local disk
How can I determine type of mysql database : whether it is InnoDB or
How can I get the controller action (method) and controller type that will be
Does anyone know how I can determine if an application is able to accept
We can determine the length of an ArrayList<E> using its public method size() ,
Is there an method like isset so I can determine if there is a
Using the sizeof operator, I can determine the size of any type – but
If I understand correctly, typeid can determine the actual type in polymorphism, while typeof

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.