• C# 不是序列化xml 转实体Model【原家独创】


    public static T XmlConvertModel<T>(string xmlStr) where T : class, new()
            {
                T t = new T();
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(xmlStr);
                foreach (XmlNode xnls in xmlDoc.ChildNodes)
                {
                    if (xnls.Name.ToUpper() == typeof(T).Name.ToUpper())
                    {
                        foreach (XmlNode xnl in xnls.ChildNodes)
                        {
                            System.Reflection.PropertyInfo[] propertyInfo = typeof(T).GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
                            foreach (System.Reflection.PropertyInfo pinfo in propertyInfo)
                            {
                                if (xnl.Name.ToUpper() == pinfo.Name.ToUpper())
                                {
                                    pinfo.SetValue(t, xnl.InnerText, null);
                                    break;
                                }
                            }
                        }
                    }
                }
                return t;

            }

  • 相关阅读:
    1059. Prime Factors (25)
    mybatis中resultType和resultMap的区别
    Spring Boot中使用Swagger2构建强大的RESTful API文档
    ES6之6种遍历对象属性的方法
    QQ授权登录
    nodejs爬虫入门
    nrm -- NPM registry 管理工具(附带测速功能)
    Sublime Text 3 使用MarkDown编写带预览的文本
    js中字符串函数indexOf与search的区别
    linux基础入门
  • 原文地址:https://www.cnblogs.com/LuoEast/p/11851984.html
Copyright © 2020-2023  润新知