1 public void EachProperties() 2 { 3 Contract contract = new Contract { employeename = "Rikas" }; 4 Type type = contract.GetType(); 5 System.Reflection.PropertyInfo[] ps = type.GetProperties(); 6 foreach (PropertyInfo i in ps) 7 { 8 if (i.PropertyType == typeof(string))//属性的类型判断 9 { 10 object obj = i.GetValue(contract, null); 11 string name = i.Name; 12 } 13 } 14 }
时间: 2024-10-07 18:03:03