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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:39:44+00:00 2026-05-11T16:39:44+00:00

I have the following code to create an expression of a func for accessing

  • 0

I have the following code to create an expression of a func for accessing a property of a class

public static Expression<Func<TObj, TProperty>> BuildGet<TObj, TProperty>(PropertyInfo property)
{
    Type type = typeof(TObj);
    ParameterExpression arg = Expression.Parameter(type, "x");
    var prop = Expression.Property(arg, property);

    return Expression.Lambda<Func<TObj, TProperty>>(prop, arg);
}

The problem is, is that I have to pass in TObj and TProperty even though they are known (properties on PropertyInfo class – .DeclaringType and .PropertyType).

Is there a way around this so I don’t explicitly have to pass them in?

The return type must remain as Expression<Func<TObj, TProperty>>

  • 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-11T16:39:44+00:00Added an answer on May 11, 2026 at 4:39 pm

    If the return type has to remain Func<TObj, TProperty> then the method has to stay generic. You will have to specify the types at compile-time. That’s the thing – although PropertyInfo knows the types, that information is only available at execution time, whereas the compiler needs to know the type information in order to check that you’re using the value properly, etc. It can’t possibly know what the execution-time values of the properties will be.

    If you could change the return type to just Expression then you could create an Expression<Func<TObj, TProperty>> with the appropriate types at execution time, but just return it as an Expression. You wouldn’t be able to use the return value in a compile-time type-safe way without casting, but it may be helpful…

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

Sidebar

Ask A Question

Stats

  • Questions 89k
  • Answers 89k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I ran into a very similar problem and here is… May 11, 2026 at 5:49 pm
  • Editorial Team
    Editorial Team added an answer $("td:not(:has(a))").doStuff(); May 11, 2026 at 5:49 pm
  • Editorial Team
    Editorial Team added an answer I feel your pain. We have a column in our… May 11, 2026 at 5:49 pm

Related Questions

This question is a result of what i noticed while trying to answer another
I have a simple function written in Oracle 9i (version 9.2.0.4.0) to simulate an
I am using the following code: <?php $stock = $_GET[s]; //returns stock ticker symbol
I am having a bit of a problem with a functor (and it's resultant
I am having some issues with using the OrderBy extension method on a LINQ

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.