zoukankan      html  css  js  c++  java
  • C# 利用反射动态给模型Model 赋值

    https://www.cnblogs.com/waitingfor/articles/2220669.html

    object ff = Activator.CreateInstance(tt, null);//创建指定类型实例
     
    https://www.cnblogs.com/guohu/p/4496510.html
    property.SetValue(obj,Convert.ChangeType(value,property.PropertyType),null);
     
    实现

                DataModel.SystemConfig systemConfig = new DataModel.SystemConfig();
                

                PropertyInfo[] ps = systemConfig.GetType().GetProperties();
                foreach (PropertyInfo p in ps)
                {
                    object obj = Activator.CreateInstance(p.PropertyType);//创建指定类型实例
                    PropertyInfo[] props = p.PropertyType.GetProperties();
                    foreach (PropertyInfo pr in props)
                    {
                        DataGridViewRow dgvr = (from item in this.rcomdgv1.Rows.Cast<DataGridViewRow>()
                                                      where item.Cells["EnName"].Value.ToString() == pr.Name
                                                      select item).FirstOrDefault();
                        pr.SetValue(obj, Convert.ChangeType(dgvr.Cells["values"].Value, pr.PropertyType),null);
                    }
                    p.SetValue(systemConfig, Convert.ChangeType(obj, p.PropertyType), null);
                }
  • 相关阅读:
    Pandas 学习记录(一)
    python 列表常用操作
    pandas 基本操作
    Numpy np.array 相关常用操作学习笔记
    JS控制背景音乐 没有界面
    Linux Awk使用案例总结
    Yii2 定时任务创建(Console 任务)
    YII2项目常用技能知识总结
    /etc/fstab readyonly 解决办法
    Redis 排行榜 自己简单练习
  • 原文地址:https://www.cnblogs.com/LuoEast/p/10554035.html
Copyright © 2011-2022 走看看