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

 

相关文章:

  • 2021-09-05
  • 2022-12-23
  • 2022-12-23
  • 2021-06-02
  • 2022-12-23
  • 2021-10-05
  • 2021-09-22
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-22
  • 2022-02-08
  • 2022-12-23
相关资源
相似解决方案