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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T05:18:20+00:00 2026-05-19T05:18:20+00:00

I have a scenario where I have to get an array of strings that

  • 0

I have a scenario where I have to get an array of strings that represent each of the property names used within a Func parameter. Here is an example implementation:

public class CustomClass<TSource>
{
  public string[] GetPropertiesUsed
  {
    get
    {
      // do magical parsing based upon parameter passed into CustomMethod
    }
  }

  public void CustomMethod(Func<TSource, object> method)
  {
    // do stuff
  }
}

Here would be an example usage:

var customClass = new CustomClass<Person>();
customClass.CustomMethod(src => "(" + src.AreaCode + ") " + src.Phone);

...

var propertiesUsed = customClass.GetPropertiesUsed;
// propertiesUsed should contain ["AreaCode", "Phone"]

The part I’m stuck on in the above is the “do magical parsing based upon parameter passed into CustomMethod.”

  • 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-19T05:18:21+00:00Added an answer on May 19, 2026 at 5:18 am

    You’ll need to change your CustomMethod to take an Expression<Func<TSource, object>>, and probably subclass the ExpressionVisitor, overriding VisitMember:

    public void CustomMethod(Expression<Func<TSource, object>> method)
    {
         PropertyFinder lister = new PropertyFinder();
         properties = lister.Parse((Expression) expr);
    }
    
    // this will be what you want to return from GetPropertiesUsed
    List<string> properties;
    
    public class PropertyFinder : ExpressionVisitor
    {
        public List<string> Parse(Expression expression)
        {
            properties.Clear();
            Visit(expression);
            return properties;
        }
    
        List<string> properties = new List<string>();
    
        protected override Expression VisitMember(MemberExpression m)
        {
            // look at m to see what the property name is and add it to properties
            ... code here ...
            // then return the result of ExpressionVisitor.VisitMember
            return base.VisitMember(m);
        }
    }
    

    This should get you started in the right direction. Let me know if you need some help figuring out the “… code here …” part.

    Useful links:

    • Expression Trees
    • How to Modify Expression Trees
    • ExpressionVisitor
    • VisitMember
    • MemberExpression
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have he following scenario: Got an HTML template file that will be used
I have a scenario where I get a count and then pass the count
I have an architecture scenario and I would like to discuss to get your
I have a very simple scenario which I cannot get to work. I am
I have a path defined: when /the admin home\s?page/ /admin/ I have scenario that
I have a scenario that does not seem to be covered in any of
I have a scenario that requires me to generate a printed page with encrypted
I have a scenario where I'm making a simple get request through a link
I have problem with the autoload function here is the scenario: Note: the MVC
I have a method fetchObjects(String) that is expected to return an array of Contract

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.