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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:36:36+00:00 2026-05-27T14:36:36+00:00

To this day, I have not found a great article about expressions – and

  • 0

To this day, I have not found a great article about expressions – and how to look at a C# lambda statement and say “oh, that’s a blah blah”… so, if you know of a good article, I’d appreciate that as an answer too.

Code sample to explain the question

So… given the following c# code:

public class SomeClass<T>
{
    public TResult SomeMethod<TResult>(Expression<Func<T, TResult>> expression)
    {
        // This is just an example... don't get hung up on this :)
        return default(TResult);
    }
}

public class Person
{
    public string FirstName { get; set; }

    public string LastName { get; set; }
}

How do I do this…

var blah = new SomeClass<Person>();

blah.SomeMethod(p => p.FirstName);

at runtime (using reflection)?

What I expect as an answer

I kinda expect something like this… but I’m sure I’m way off with my choice of expressions.

// By the way, these values are being passed to me... so you
// can't change this part of the question :)
Type personType = typeof(Person);
string propertyName = "FirstName";

// THIS CODE BELOW IS OBVIOUSLY WRONG, BUT YOU GET THE IDEA OF
// WHAT I HOPE TO DO... THIS LINE OF CODE BELOW IS **ALL** I'M
// ASKING HOW TO DO :)
var expression = Expression.MakeUnary(ExpressionType.Lambda,
    Expression.Property(Expression.Parameter(personType, "p"),
    propertyName), typeof(string));

blah.SomeMethod(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-05-27T14:36:36+00:00Added an answer on May 27, 2026 at 2:36 pm

    Try this:

    var functorParam = Expression.Parameter(typeof(Person));
    var lambda = Expression.Lambda(
        Expression.Property(functorParam, typeof(Person).GetProperty("FirstName"))
    ,   functorParam /* <<= EDIT #1 */
    );
    blah.SomeMethod((Expression<Func<Person,string>>)lambda); /* EDIT #2 */
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been messing with this all day and have still not found a solution.
I have this little script that shows one wisdom each day. so I have
i have searched the web relentlessly for this and have not found anything -
I may seem ignorant but I have not found much information about how to
I have been struggling with this all day. I have an html table in
This is the day of weird behavior. We have a Win32 project made with
I have been struggling with this yesterday whole day, and still couldnt figure it
I have been banging my head on this one all day. The C++ project
OKay I lost alsmost the whole day on this. I have a webapp where
I have been trying this for the whole day and I managed to make

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.