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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:52:04+00:00 2026-05-30T03:52:04+00:00

I have a class MyDummyClass to which I’d like to pass some properties in

  • 0

I have a class MyDummyClass to which I’d like to pass some properties in form of a Lambda expression for a later evaluation. So what I can do something like

public class MyDummyClass<T>
{
    public MyDummyClass(Expression<Func<T, object>> property)
    {
        ...
    }
    ...
}

..and then use that class like new MyDummyClass<Person>(x=>x.Name), right?

But then I’d like to pass not only a single property but a list of properties. So I’d write my class like

public class MyDummyClass<T>
{
    public MyDummyClass(IEnumerable<Expression<Func<T, object>>> properties)
    {
        ...
    }
    ...
}

and I’d like to use it like new MyDummyClass<Person>(new[] { x=>x.Name, x=>x.Surname }) but unfortunately that doesn’t work! Instead I have to write

new MyDummyClass<Person>
     (new Expression<Func<Person, object>>[] { x=>x.Name, x=>x.Surname});

But this is a bit awkward to write, isn’t it? Of course, using params would work, but this is just a sample out of a more complicated piece of code where using params is not an option.
Does anyone have a better option to come 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-30T03:52:06+00:00Added an answer on May 30, 2026 at 3:52 am

    You could try:

    public class MyDummyClass<T>
    {
        public MyDummyClass(Expression<Func<T, object>> expression)
        {
            NewArrayExpression array = expression.Body as NewArrayExpression;
            foreach( object obj in ( IEnumerable<object> )( array.Expressions ) )
            {
                Debug.Write( obj.ToString() );
            }
        }
    }
    

    And then you would call it like this:

    MyDummyClass<Person> cls = new MyDummyClass<Person>( item => new[] { item.Name, item.Surname } );
    

    The problem is this won’t give you the value of the property because no actual Person instance it specified Doing a ToString on “obj” will give you the name of the property. I don’t know if this is what you’re after, but it maybe a starting point.

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

Sidebar

Related Questions

I have class and properties in there. Some properties can be marked attribute (it's
I have class GUI so I can create object like this: GUI g1 =
I have class (MyCustomWebView) that extend webview can i do something like this ?
I have class method that returns a list of employees that I can iterate
I have class A, which exposes an event. an object of class B subscribed
I have class which implements Countable, ArrayAccess, Iterator and Serializable. I have a public
I have: class Foo(models.Model): pass class Bar(Foo): pass class Corn(Foo): pass # Now I
I have class like public class ProgressBars { public ProgressBars() { } private Int32
I have class MasterData whose instances contain some general information about all possible gadgets.
I have class methods like these in a message model: def delete_all_users_messages(user_id, parent_id) message

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.