Quantcast
Channel: Windows Forms General forum
Viewing all articles
Browse latest Browse all 12583

looping through nested object properties in c#

$
0
0

I have an objects like this

public class WEntity
    {
        string exStirng;

        public string EtcStirng
        {
            get { return exStirng; }
            set { exStirng = value; }
        }
        xEntity info;

        public xEntity Info 
        {
            get { return info; }
            set { info = value; }
        }
        yEntity adress;

        public yEntity Adress
        {
            get { return adress; }
            set { adress = value; }
        }
        zEntity[] blala;

        public zEntity[] Blala
        {
            get { return blala; }
            set { blala = value; }
        }
 }
I

am looking loop through all propertis in objects and add them as key value to my Item object.

for given object

key=exString 
value=exstringValue
items.Add(item)

then

 foreach (PropertyInfo pInfo in XEntity properties)
  {

                item = new Item();
                item.Label = pInfo.Name;

                item.Value = pInfo.Value;
                items.Add(item);              
 }

 foreach (PropertyInfo pInfo in YEntity properties)
  {

                item = new Item();
                item.Label = pInfo.Name;

                item.Value = pInfo.Value;
                items.Add(item);              
 }

foreach(zEntity ent in blabla)
{
      //Add all ent properties and values to Item Object
}

What's the best way to do this?


kadirzade


Viewing all articles
Browse latest Browse all 12583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>