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

The Archive Base Latest Questions

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

Within the following method, I would like to access any optional arguments that are

  • 0

Within the following method, I would like to access any optional arguments that are contained within the Action:

public static class ValidatorEngine
{
    public static void Validate(Action someMethodWithOptionalArguments)
    {
        object target = someMethodWithOptionalArguments.Target;
    }
}

So if I called this method like so:

ValidatorEngine.Validate(() => UpdateByModel(model));

I would like to be able to access the model argument passed into the Action. I’m not even interested in invoking this Action.

I’m thinking that there is something that can be done with the Target property of the Action because I can see the model when debugging. I just can’t figure it out programmatically.

  • 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-20T09:38:05+00:00Added an answer on May 20, 2026 at 9:38 am

    If you want to inspect it but not execute it, this is a prime example for an Expression. Just change the signature from Action to Expression<Action>. This will give you an expression tree that you can analyse. For a basic example:

    public static class ValidatorEngine
    {
        static void Main()
        {
            string model = "abc";
            ValidatorEngine.Validate(() => UpdateByModel(model));
        }
        public static void Validate(Expression<Action> action)
        {
            var methodCall = action.Body as MethodCallExpression;
            if (methodCall == null) throw new InvalidOperationException("Expected a method-call");
            Console.WriteLine("Method: " + methodCall.Method.DeclaringType.Name + "." + methodCall.Method.Name);
            var parameters = methodCall.Method.GetParameters();
            for (int i = 0; i < parameters.Length; i++)
            {
              Console.WriteLine(parameters[i].Name + ": " + Evaluate(methodCall.Arguments[i]));
            }
        }
    
        static object Evaluate(Expression exp)
        {
            switch (exp.NodeType)
            {
                case ExpressionType.Constant:
                    return ((ConstantExpression)exp).Value;
                case ExpressionType.MemberAccess:
                    var me = (MemberExpression)exp;
                    switch (me.Member.MemberType)
                    {
                        case System.Reflection.MemberTypes.Field:
                            return ((FieldInfo)me.Member).GetValue(Evaluate(me.Expression));
                        case MemberTypes.Property:
                            return ((PropertyInfo)me.Member).GetValue(Evaluate(me.Expression), null);
                        default:
                            throw new NotSupportedException(me.Member.MemberType.ToString());
                    }
                default:
                    throw new NotSupportedException(exp.NodeType.ToString());
    
            }
    
        }
        static void UpdateByModel(object model) {
            throw new NotImplementedException();
        }
    }
    

    To support a richer set of nodes and scenarios, see this richer version.

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

Sidebar

Related Questions

Within a public class that doesn't extend any other class I'm doing some evaluation
I would like to access the Foo instance foo within my manager method baz
I have an enum class like the following: public enum Letter { OMEGA_LETTER(Omega), GAMMA_LETTER(Gamma),
I have a Data Access Layer library that I would like to make portable.
I would like to injecte a decorator on a method class from another class.
I have the following C# method: private string[] test() { } I would like
I'm trying to do the following: Run a Worker and a method within it
I'd like double quotes to appear within the following string so it looks like:
I'm using the following code within the JCProperty class to retrieve data from a
For a Rails app, I would like to overload or modify Kernel::load such that

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.