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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:45:34+00:00 2026-06-08T02:45:34+00:00

I am trying to find via reflection the most appropriate method to invoke, when

  • 0

I am trying to find via reflection the most appropriate method to invoke, when i have a type to pass to that method.

The edge case that is worrying me is overloading with same number of parameters, like so:

class UserClass {}
class UserClassB : UserClass {}

class SomeClass {
   void method(object x);
   void method(UserClass x);
}

in runtime i am interested in invoking method, while the type i have in hand is UserClassB.

The most appropriate would be method(UserClass).

The problem is that when using typeof(SomeClass).GetMethod("method", new Type[] { typeof(UserClass2) })); it will return a null, cause i think it searched based on exact match for the passed types.

Any ideas? 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-06-08T02:45:37+00:00Added an answer on June 8, 2026 at 2:45 am

    You’re missing the binding flags.
    use overload that you can pass the following flags:
    BindingFlags.Instance | BindingFlags.NonPublic

    you’re getting null because the GetMethod will look for public method unless you specify you want non public methods too.

    var method = typeof(SomeClass).GetMethod("method", BindingFlags.Instance | BindingFlags.NonPublic, null, new[] { typeof(UserClass) },null);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying find a way to have PHP to indicate to the browser that
I am trying to call a .dll's method via reflection, but am getting a
I am trying to find HTML tags, via PHP ereg, that has a {xxx}
I'm trying to find an IOC container that will allow me to have mapping
Trying to find a good name for a method swapping each coordinate X and
Trying to find an example that has css rollover using sprites & sliding door
While trying to find an answer to Android Jasper Reporting I found out that
I'm trying to find a property that indicates how iPhone physically obtains CLLocation ?
I'm trying to find a simple way of checking user stats via FTP, wininet
I am trying to find out how many times a gem was installed via

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.