C#遍历对象属性

 1 public void EachProperties()
 2 {
 3     Contract contract = new Contract { employeename = "Rikas" };
 4     Type type = contract.GetType();
 5     System.Reflection.PropertyInfo[] ps = type.GetProperties();
 6     foreach (PropertyInfo i in ps)
 7     {
 8     if (i.PropertyType == typeof(string))//属性的类型判断
 9     {
10         object obj = i.GetValue(contract, null);
11         string name = i.Name;
12     }
13     }
14 }

 

posted @ 2016-03-11 09:55  RC7  阅读(3372)  评论(0编辑  收藏  举报