首页 > 其他 > 详细

C#遍历实体的所有属性并为属性赋值

时间:2014-08-15 19:17:29      阅读:542      评论:0      收藏:0      [点我收藏+]
using System.Reflection;
  
class Config
{
    public string encoding { get; set; }
    public string plugins { get; set; }
}

将hashtable的key值赋给实体类config.

Hashtable ht = new Hashtable();
  
ht.Add("encoding", "utf8");
ht.Add("plugins", "xxxx");
Config config = new Config();
PropertyInfo[] propertys = config.GetType().GetProperties();
foreach (PropertyInfo property in propertys)
{
    for (int i = 0; i < ht.Count; i++)
    {
        property.SetValue(config, ht[property.Name].ToString(), null);
    }
}

C#遍历实体的所有属性并为属性赋值,布布扣,bubuko.com

C#遍历实体的所有属性并为属性赋值

原文:http://www.cnblogs.com/skyAL/p/3915402.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!