C#利用反射,遍历获得一个类的所有属性名,以及该类的实例的所有属性的值



属性类 temp = new 属性类();

string s = string.Empty; foreach (System.Reflection.PropertyInfo info in typeof(类名.属性类).GetProperties())
{
  txtResult.AppendText(
""+info.Name + "】:"+info.GetValue(temp, null) + "\r\n");
}



输出结果:

【itemId】:3580447722220
【title】:2014四大容量大包手提单肩包女士包
【pic_url】:http://img02.taobaocdn.com/bao/uploaded/i2/T1Eg3YXixgXXXXX444444XXX_!!0-item_pic.jpg_460x460.jpg
【shopId】:691224444243
【shopIndex】:http://shop69124444442243.taobao.com
【sellerNick】:******
【price_a】:168.99
【price_b】:25.99
【sales】:18
【CommentCount】:381
【pv】:35419

 

 

posted on 2014-03-25 22:29  nanphon  阅读(259)  评论(0编辑  收藏  举报

导航