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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:33:24+00:00 2026-06-02T01:33:24+00:00

I asked similar questions here And here This is a sample Type: public class

  • 0

I asked similar questions here And here

This is a sample Type:

    public class Product {

    public string Name { get; set; }
    public string Title { get; set; }
    public string Category { get; set; }
    public bool IsAllowed { get; set; }

}

And I have a Generic class that needs properties to generate some HTML codes:

public class Generator<T> {

    public T MainType { get; set; }
    public List<string> SelectedProperties { get; set; }

    public string Generate() {

        Dictionary<string, PropertyInfo> props;
        props = typeof(T)
                .GetProperties()
                .ToDictionary<PropertyInfo, string>(prop => prop.Name);

        Type propType = null;
        string propName = "";
        foreach(string item in SelectedProperties) {
            if(props.Keys.Contains(item)) {
                propType = props[item].PropertyType;
                propName = item;

                // Generate Html by propName & propType
            }
        }

And I use this types as following:

Product pr = new Product();
Generator<Product> GT = new Generator<Product>();
GT.MainType = pr;
GT.SelectedProperties = new List<string> { "Title", "IsAllowed" };

GT.Generate();

So I think this process should be more easy as is but I don’t know how implement it, I think to pass properties to the generator more simple, something like the followings Pseudo-code:

GT.SelectedProperties.Add(pr.Title);
GT.SelectedProperties.Add(pr.IsAllowed);

I don’t know is this possible or not, I need just two things 1-PropertyName like: IsAllowed 2- property type like : bool. Maybe don’t need to pass MainType I use it to get property types so if I can handle like the above don’t need it any more.

What is your suggestion to implement something like this?

Is there any better way to do this?

Update

As ArsenMkrt said I found can use MemberExpression but I can’t get Property Type, I see the property type in debugging see the picture:

enter image description here

So how can I get property type?

I found it here.

  • 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-06-02T01:33:26+00:00Added an answer on June 2, 2026 at 1:33 am

    You can use expression tree, than your code will look like this

    GT.SelectedProperties.Add(p=>p.Title);
    GT.SelectedProperties.Add(p=>p.IsAllowed);
    

    You will need to create custom collection class derived from List for SelectedProperties and create add method like this

       //where T is the type of your class
       public string Add<TProp>(Expression<Func<T, TProp>> expression)
       {
            var body = expression.Body as MemberExpression;
            if (body == null) 
                throw new ArgumentException("'expression' should be a member expression");
            //Call List Add method with property name
            Add(body.Member.Name);
       }
    

    Hope this helps

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

Sidebar

Related Questions

Similar questions to this have been asked a number of times here, but none
I realize that similar questions have been asked about this before here on SO,
I found this on Google, click here , which someone asked a similar question,
Similar questions have been asked, but nothing exactly like mine, so here goes. We
I didn't see any similar questions asked on this topic, and I had to
Questions similar to this have been asked all over, but I haven't been able
I've looked at a bunch of resources provided by similar questions asked on this
I found similar questions asked here but there weren't answers to my satisfaction. So
I see that there have been similar questions asked here regarding wrapping unmanaged C++
I know very similar questions were asked here in the past - but neither

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.