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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:36:51+00:00 2026-06-12T15:36:51+00:00

Is there a simple way of finding out if an Expression contains a ParameterExpression

  • 0

Is there a simple way of finding out if an Expression contains a ParameterExpression that isn’t further wrapped in for example a MemberExpression.

Example:

x => x.Method() ? x : null <= 1 occurence of x without any further evaluation

x => x.Method() ? x.Property : null <= 0 occurences of x without any further evaluation

Simply put my use case is that I know the Method (no params) and Property values and want to find out if this is enough to evaluate the expression without fetching the entire “object” from store.

Edit:
My example is maybe to simplified. There are more Expression types that needs to be handled (for example UnaryExpression).

x => ((Cast) x).Property <= 0 occurences of x without any further evaluation

I’m looking for an answer to the following question:

given an expression, if I know all method return values and property values of the input parameter but not the parameter value itself, can I evaluate the expression?

  • 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-12T15:36:52+00:00Added an answer on June 12, 2026 at 3:36 pm

    If you are on .NET 4 or later, you can use ExpressionVisitor for this.

    I’m not quite sure how you define “lonely parameter”, but if you want to exclude direct method calls, member accesses and indexer accesses on parameters, you can use something like this (untested):

    Use it like this:

    new MyExpressionVisitor().GetNumLonelyParameterExpressions(myExpression.Body)
    

    public class MyExpressionVisitor : ExpressionVisitor
    {
        private int numLonelyParameterExpressions;
    
        public int GetNumLonelyParameterExpressions(Expression expression)
        {
            numLonelyParameterExpressions = 0;
            Visit(expression);
            return numLonelyParameterExpressions;
        }
    
        protected override Expression VisitParameter(ParameterExpression node)
        {
            // Every time we encounter a lonely parameter, increment.
            numLonelyParameterExpressions++;
            return base.VisitParameter(node);
        }
    
        protected override Expression VisitMethodCall(MethodCallExpression node)
        {
            // Don't visit parameters that have methods called on them.
             var expr = (node.Object is ParameterExpression)
                ? Expression.Default(node.Object.Type)
                : node.Object;
    
            // We need to make sure the arguments are visited though.
            return base.VisitMethodCall(node.Update(expr, node.Arguments));
        }
    
    
        protected override Expression VisitMember(MemberExpression node)
        {
              // Don't visit parameters with member accesses on them.
              if (node.Expression is ParameterExpression)
                  return Expression.Default(node.Type);
    
              return base.VisitMember(node);
        }
    
        protected override Expression VisitIndex(IndexExpression node)
        {
             // Same idea here.
             var expr = (node.Object is ParameterExpression)
                 ? Expression.Default(node.Object.Type)
                 : node.Object;
    
             return base.VisitIndex(node.Update(expr, node.Arguments));
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a simple way of finding out if a file is on the
Is there a simple way of finding out what 'this object' is?
Is there a simple way of finding out the current value of a specified
Is there a simple way to get time time of day (17:30, 01:20...etc) that
Is there a way of finding out when the data was last entered into
Is there a simple way to insert the current time (like TIME: [2012-07-02 Mon
Is there a simple way to serialize a single-level structure as a string for
Is there a simple way, possibly with open-source command line tools in Linux, to
Is there a simple way in Symfony 1.4 to know whether a submitted form
Is there a simple way to move an element inside its own parent? Like

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.