Home How to get and set values of properties using reflection
Reply: 0

How to get and set values of properties using reflection

user1035
1#
user1035 Published in May 25, 2018, 2:36 pm

I want to get the properties of my class which looks like this:

public class Model
{
    public Content Intro { get; set; }
    public List<Content> Intro2 { get; set; }
    public Content Intro3 { get; set; }
    public List<MegaContent> Intro4 { get; set; }
}

After getting the properties, I want to set their values to be decoded. So, for example, Content has properties of title, description etc, I want each to be html decoded, as well as product has some properties which need to be decoded.

What I have done so far:

    foreach (var v in homePage.GetType().GetProperties())
    {
        foreach (var p in v.PropertyType.GetProperties())
        {
            // if(p.Name.Contains("title") {
            //     // it will be html encoded, i want to use WebUtility.HtmlDecode(property);
            // }
            // also, I want to iterate through each element of the list (if it's a list property)
        }
    }
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.336529 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO