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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:06:46+00:00 2026-05-16T06:06:46+00:00

let there be: Expression<Func<Customer, bool>> expression = c => c.Name == John; now i

  • 0

let there be:

Expression<Func<Customer, bool>> expression = c => c.Name == "John";

now i get the value by using :

string myvalue = ((ConstantExpression) bin.Right).Value;

now let there be:

string x = "John";
Expression<Func<Customer, bool>> expression = c => c.Name == x;

now i understand that

string myvalue = ((ConstantExpression) bin.Right).Value;

would generate an error because the bin.right here is not constantexpression its a field expression but the question is how do i get the value(John) out of this ?

  • 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-16T06:06:47+00:00Added an answer on May 16, 2026 at 6:06 am

    You could wrap the expression in a lambda and then compile and evaluate it. That would give you the value no matter what kind of expression it is.

    string myvalue = Expression.Lambda<Func<string>>(bin.Right).Compile().Invoke();
    

    Note that this won’t work if the parameter c is used on the right hand side of the expression, since it wouldn’t be defined. Also note that this will give you the current value of the right hand side when you call Invoke, and subsequent calls could return different values if the field in the object changes.


    Update: If you don’t know the type of the right hand side at compile time, you can use object, but this will break for value types like int. You will need to use Expression.Convert to force value types to be boxed before returning them. This will work for both value types and reference types:

    object myvalue = Expression.Lambda<Func<object>>(
        Expression.Convert(bin.Right, typeof(object))).Compile().Invoke();
    

    You could also use an untyped lambda and DynamicInvoke:

    object myvalue = Expression.Lambda(bin.Right).Compile().DynamicInvoke();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

let there be : Expression<Func<Message, bool>> exp1 = x => x.mesID == 1; Expression<Func<MessageDTO,
I try using let to define an expression definition, but all I get is
A string representation of an object instance property can be taken with Expression<Func<T>> :
Is it possible to send an expression to a method, get the method name
Let's say there is a multiplayer game defined as such: var GameSchema = new
Let's assume there is a static .Net method static void RegisterDelegate(Action<array<Object^>^>^ handler); defined in
Let's say there is a page with 100 different user photo's shown on the
Let's say there is a file called myfile.txt with the following contents: one two
Let's say there's a table created as follows: create table testTable ( colA int
Let's say there are two python scripts that want to write data to the

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.