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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:16:26+00:00 2026-05-25T18:16:26+00:00

I have a working setup which is not strongly typed and relies on reflection.

  • 0

I have a working setup which is not strongly typed and relies on reflection.

I have a class, say

class Person{

    public string FirstName {get ; set;}
    public string LastName {get; set;}
    public int Age {get; set;}
    ...  
    // some more public properties
}

and

class CellInfo {
     public string Title {get; set;}
     public string FormatString {get; set;}
}

and I have a dictionary like this

Dictionary<string, CellInfo> fields = new Dictionary<string, CellInfo>();
fields.Add("FirstName", new CellInfo {Title = "First Name", FormatString = "Foo"});
fields.Add("LastName", new CellInfo {Title = "Last Name", FormatString = "Bar"});

It’s a simple dictionary with property Names and some info about them.
I pass the dictionary to another module that processes Person instances and I do

Dictionary<string, CellInfo> fields = SomeMethodToGetDictionary();
foreach(Person p in someCollection)
{
    foreach(var field in fields)
    { 
       object cellValue = type(Person).GetProperty(field.Key).GetValue(p, null);
       // use cellValue and info on field from field.Value somewhere.
       ...
    }
 }

This method of passing the string for field name and using reflection works, but I was wondering if there is a strongly-typed method of doing this.

What I had in mind was having a property that stored a linq expression, something like this

fields.Add("FirstName", new CellInfo 
                   {
                      Title = "First Name", 
                      FormatString = "Foo",
                      EvalExpression = p => p.FirstName
                   });

and during usage, somehow use the EvalExpression on a person object and get the property value. I have no clue where to begin or what the syntax would be like to have a property like this that’s evaluateable. I’m new to function delegates and expression trees that I don’t even know the right keywords to search for. Hope my description is clear; if not, let me know and I’ll details as necessary.
Any assistance would much appreciated.

  • 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-25T18:16:27+00:00Added an answer on May 25, 2026 at 6:16 pm

    You can try something like this to not have to code the property names as strings if this is what you mean by saying strongly typed:

    class CellInfo<T>
    {
        public string Title { get; set; }
        public string FormatString { get; set; }
        public Func<T, object> Selector { get; set; }
    }
    
    Dictionary<string, CellInfo<Person>> dict = new Dictionary<string, CellInfo<Person>>();
    
    dict.Add("LastName", new CellInfo<Person> { Selector = p => p.LastName });
    dict.Add("Age", new CellInfo<Person> { Selector = p => p.Age });
    
    foreach (Person p in someCollection)
    {
        foreach (var cellInfo in dict)
        {
            object value = cellInfo.Value.Selector(p);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have nexus 1.5.0 setup to proxy springsource repositories but it's not working. The
I have a fully working Setup project within Visual Studio 2008 that takes inputs
I have the whole setup working for months on my local computer. I'm installing
I have a (from what I can tell) perfectly working Linux setup (Ubuntu 8.04)
I have a site setup that is working fine in ie8 and firefox but
I'm working on a survey system for my company and I have it setup
I'm working on an online store. I have it setup on my testing server.
I have Thinking Sphinx setup and working however I am having a problem getting
I have this somewhat working though it's important to understand the setup. With multi-domain
I have the following setup: I'm working with C++ projects under a custom build

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.