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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:31:32+00:00 2026-05-28T02:31:32+00:00

I want to write this in C#: SomeUnknownType x; SuperDuperInvoke(x, MethodName, param1, param2, param3);

  • 0

I want to write this in C#:

SomeUnknownType x;

SuperDuperInvoke(x, "MethodName", param1, param2, param3);

SuperDuperInvoke2(x, "MethodName", "param1String", "param2String", "param3String");

Get some object I know nothing about, a method name, and a list of parameters, and just call the method. SuperDuperInvoke2 assumes the parameters are convertible from string.

I assume something like this is possible using the dynamic framework… I just can’t find how…

I know I can do this with Reflection, but it’s ugly and annoying…


I’ll explain myself a little.

I want to use this for integration testing of some business server.
The server has a lot of different components that can handle requests, all loaded into an IoC container.
I need to expose some of thees components, mostly for testing, so I want to just receive the name of the component, what method i should call with what parameters and just call it.

  • 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-28T02:31:32+00:00Added an answer on May 28, 2026 at 2:31 am

    I know you wrote that you don’t like Reflection but is this really all that ugly?

    var result = x.GetType().GetMethod( "MethodName" ).Invoke( x, new object[] { methodParams });
    

    If the method could be overloaded you can’t go by name only but also need to know how many parameters you are going to invoke it with. Something like this

    var method = x.GetType()
                  .GetMethods()
                  .First(m => m.Name == "MethodName" && m.GetParameters().Length == 2);
    var result = method.Invoke( x, new object[] { methodParams });
    

    This will not work if you also need to match your methodParams by type.

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

Sidebar

Related Questions

I have some xml encoded as UTF-8 and I want to write this to
I want to write some html code in php. In this html code I
I write this in api v2: map.enableGoogleBar(); I want to using v3, but I
The code that I want to write is like this: void MethodOnThreadA() { for
Is there a better way to write this code? I want to show a
I want to write a query like this: SELECT o.OrderId, MAX(o.NegotiatedPrice, o.SuggestedPrice) FROM Order
I want to write a String to a Stream (a MemoryStream in this case)
I often find I want to write code something like this in C#, but
I want to load this simple something into my Editor: Write:-repeat,write(hi),nl,fail. So that it
this is my code that I write it but I want to use LINQ

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.