.NET 反射机制

来源:互联网 发布:java重写例子 编辑:程序博客网 时间:2024/05/20 12:48
IList list;//取得List对象里面的所有属性PropertyInfo[] propertys = list[0].GetType().GetProperties();//遍历属性foreach (PropertyInfo pi in propertys){ result.Columns.Add(pi.Name, pi.PropertyType);}//遍历Listfor (int i = 0; i < list.Count; i++){ ArrayList tempList = new ArrayList(); //遍历属性 foreach (PropertyInfo pi in propertys) { //遍历类里面的属性..并取出 object obj = pi.GetValue(list[i], null); tempList.Add(obj); //也可以根据属性名...取属性值 //list[i].GetType().GetProperty(fieldName); //Object objValue = pi.GetValue(line, null); }}
原创粉丝点击