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);
                }
            }


你可能感兴趣的:(C#遍历实体的所有属性并为属性赋值)