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);
                }
            }

 

 posted on 2012-07-06 10:53  vingi_苍月  阅读(7682)  评论(0编辑  收藏  举报