• 反射原理读取对象属性并设置属性值


     Dictionary<string, string> dicNodes = new Dictionary<string, string>();
           foreach (XmlNode node in nodes.ChildNodes)
           {
               if (node.NodeType==XmlNodeType.Element)
               {
                 
                  dicNodes.Add(node.Attributes["name"].Value,node.Attributes["value"].Value);
               }
           }
            tb_b_employee Employee = new tb_b_employee();
    
            Type type = Employee.GetType();
           //取得属性集合
           PropertyInfo[] pi = type.GetProperties();
           foreach (PropertyInfo item in pi)
           {
               //给属性赋值
               if (dicNodes[item.Name] != null)
               {
                   item.SetValue(Employee,dicNodes[item.Name], null);
               }
           }
    

      

  • 相关阅读:
    vmalloc详解
    SSD 页、块、垃圾回收
    ext2文件系统
    slub分配object
    slab分配object
    ACCESS_ONCE的作用
    CFS理论模型
    代码规范
    About Me
    SDOI R2 咕咕记
  • 原文地址:https://www.cnblogs.com/liang-ling/p/3910449.html
Copyright © 2020-2023  润新知