遍历一个类的字段和值

mozc是要遍历的类名

p.name是字段名

p.GetValue是字段名对应的值

foreach (System.Reflection.PropertyInfo p in mozc.GetType().GetProperties())
{
XmlElement name = doc.CreateElement(p.Name);
name.InnerText = p.GetValue(mozc, null).ToString();

work1.AppendChild(name);
}

posted @ 2018-05-15 11:01  就爱敲代码  阅读(262)  评论(0编辑  收藏  举报