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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:19:33+00:00 2026-05-18T11:19:33+00:00

How do I get the parameters passed into an Action<T> ? The code example

  • 0

How do I get the parameters passed into an Action<T> ? The code example should highlight what I’m trying to achieve. Sorry that it’s a little bit long.

public class Program
{
    public static void Main(string[] args)
    {
        var foo = new Foo();
        foo.GetParams(x => x.Bar(7, "hello"));
    }
}

public class Foo
{
    public void Bar(int val, string thing) { }
}

public static class Ex
{
    public static object[] GetParams<T>(this T obj, Action<T> action)
    {
        // Return new object[] { 7, "hello" }
    }
}

The only options that look vaguely useful are GetInvocationList(), Method and Target. But none of them seem to contain the data I’m after (I think it’s because of the way I’ve declared the Action). Thanks

EDIT: It’s not the types I want, it’s the actual values – as noted in the commented bit of code.

  • 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-18T11:19:33+00:00Added an answer on May 18, 2026 at 11:19 am

    To do that, it should actually be an Expression<Action<T>>. Then it is a case of decomposing the expression. Fortunately I have all the code for that over in protobuf-net, here – in particular ResolveMethod, which returns the values in the out array (after walking any captured variables, etc).

    After making ResolveMethod public (and removing everything above ResolveMethod), the code is just:

    public static object[] GetParams<T>(this T obj, Expression<Action<T>> action)
    {
        ProtoClientExtensions.ResolveMethod<T>(
            action, out Action ignoreThis, out object[] args);
        return args;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that codeIgniter turns off GET parameters by default. But by having everything
I'm trying to get quoted parameters of a bash script to safely be received
When I create a constructor with parameters using Resharper's 'Generate code' feature, I get
Is it possible to get the number of parameters being passed to a method
How can I parse the query string (GET / POST parameters) sent to an
What is the simplest way to identify and separate GET and POST parameters from
Is it possible to get the text of an OleDbCommand with all parameters replaced
Is it possible to pass parameters with an HTTP get request? If so, how
Is there any way to create the query parameters for doing a GET request
When i give wrong number of parameters in a function , i get errors.

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.