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 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

I would like to access the Foo instance foo within my manager method baz
I'm using the following code within the JCProperty class to retrieve data from a
I got nabbed by the following bug again and would like some clarification to
I have a method that looks like this: try { doStuff(); } catch (Exception
I'm using the following code within a VB 6.0 application to allow give the
I have the following Macro I want to call from within an AutoHotkey script
I have the following HTML to center images and links within a layer: edit:
Within Ruby on Rails applications database.yml is a plain text file that stores database
I have code running in an ascx within PageLayout within SharePoint 2007 that accesses
Within an application, I've got Secret Keys uses to calculate a hash for an

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.