C#遍历实体的所有属性并为属性赋值

C#遍历实体的所有属性并为属性赋值

 

           SiteInfo siteInfo=new SiteInfo();
            XmlNode node = null;
            PropertyInfo[] propertys = siteInfo.GetType().GetProperties();
            foreach (PropertyInfo property in propertys)
            {
                node=xmlDoc.GetElementsByTagName(property.Name.ToLower())[0];
                if (node != null)
                {
                    property.SetValue(siteInfo, node.InnerText, null);
                }
            }

 

命名空间:System.Reflection

http://www.xuehai.net/

你可能感兴趣的:(C#)