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;

}

C# 不是序列化xml 转实体Model【原家独创】的更多相关文章

  1. C#.NET XML 与 实体 MODEL 互转,非序列化

    只能处理简单结构XML 和 实体. using System.Text; using System.Xml; namespace A.Util { public static class MyXmlU ...

  2. c# XML和实体类之间相互转换(序列化和反序列化)[砖]

    link: http://blog.okbase.net/haobao/archive/62.html by: 好饱 我们需要在XML与实体类,DataTable,List之间进行转换,下面是XmlU ...

  3. C# XML和实体类之间相互转换(序列化和反序列化)

    我们需要在XML与实体类,DataTable,List之间进行转换,下面是XmlUtil类,该类来自网络并稍加修改. using System; using System.Collections.Ge ...

  4. XML和实体类之间相互转换(序列化和反序列化)

    我们需要在XML与实体类,DataTable,List之间进行转换,下面是XmlUtil类,该类来自网络并稍加修改. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ...

  5. 用C#实现XML和实体类之间序列化和反序列化相互转换

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.I ...

  6. asp.net webapi 序列化为xml 时实体属性增加<![CDATA[]]>防止特殊字符

    有时webapi在序列化xml时,可能需要给某些带有html或特殊字符(如 < > & /)的字段加上<![CDATA[]]> 已防止影响xml正常数据,如果使用.as ...

  7. 微信支付的JAVA SDK存在漏洞,可导致商家服务器被入侵(绕过支付)XML外部实体注入防护

    XML外部实体注入 例: InputStream is = Test01.class.getClassLoader().getResourceAsStream("evil.xml" ...

  8. WCF中序列化(XML\JSON\Dt)

    序列化 是将对象转换为容易传输的格式的过程.例如,可以序列化一个对象,然后使用 HTTP 通过 Internet 在客户端和服务器之间传输该对象.反之,反序列化根据流重新构造对象. 序列化描述了持久化 ...

  9. XML与 实体的相互转化

    using System; using System.Linq; using System.Xml; using System.Reflection; using System.Data; using ...

随机推荐

  1. Python判断是否是闰年

    year = 2012 if year % 100 != 0 and year % 4 == 0: print('闰年') elif year % 100 == 0 and year % 400 == ...

  2. windows下安装node【转】

    windows下安装node报错2503.2502 windows下命令行安装,首先使用管理员权限获取cmd msiexec /package node-v10.16.0-x64.msi 根据提示一步 ...

  3. webpack 相关文章

    webpack loader原理 由于webpack是基于Node的所以webpack只能识别.js文件,所以针对其他的文件就需要转译,这时候就需要用到我们的loader了. https://blog ...

  4. Web Service 和 WCF的比较

    Web Service 和WCF的比较 Web Service 的工作原理 Web Service也叫XML Web Service WebService是一种可以接收从Internet或者Intra ...

  5. window TOMCAT 端口被占用了怎么办?

    查看80端口被哪些程序占用了 netstat -ano|findstr "80" 根据pid(进程id) 查询对应的应用程序 tasklist|findstr "1828 ...

  6. Locust-参数化批量注册(还没试,目测试可以的)

    前言 实现场景:所有并发虚拟用户共享同一份测试数据,并且保证虚拟用户使用的数据不重复.例如,模拟10用户并发注册账号,总共有100个手机号,要求注册账号不重复,注册完毕后结束测试 准备数据 虚拟用户 ...

  7. 【翻译】The Broadcast State Pattern(广播状态)

    本文翻译自官网:The Broadcast State Pattern Provided APIs (提供的api) BroadcastProcessFunction and KeyedBroadca ...

  8. jenkins安装插件一直不动

    刷新界面即可,查看已安装的插件即可,这个时候已经安装完了,不用重启,直接使用插件即可

  9. selenium IDE下载安装(For Chrome and firefox)

    安装好Firefox/cheome之后,接下来就到了正式安装Selenuim IDE的时候了. 步骤一:下载Selenuim IDE       方法一:之前从网上查到很多安装教程,都是从http:/ ...

  10. 【Tools】三款笔记本电脑硬件检测工具-官网下载

    一.CPU-Z 下载地址: https://www.cpuid.com/softwares/cpu-z.html 描述: CPU-Z已经是大名鼎鼎了.这里就不多说了.  二.Cinebench   下 ...