1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
public class PP { public string a { get; set; } public string b { get; set; } public string c { get; set; } } class Program { static void Main(string[] args) { Hashtable ht = new Hashtable(); ht.Add("a", "utf8"); ht.Add("b", "xxxx"); ht.Add("c", "xxxx"); PP config = new PP(); 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); } } Console.WriteLine(config.a+"\t"+config.b); Console.ReadLine(); } } |