C#迭代器
1.C#获取object对象属性值
object对象属性值获取
1 private void button3_Click(object sender, EventArgs e)
2 {
3 xlsCell cel=new xlsCell(1,100);
4 List<object> lis=GetPropertyValue(cel);
5 string s=string.Empty;
6 foreach (object o in lis)
7 {
8 s += string.Format("_{0}", o.ToString());
9 }
10 MessageBox.Show(s);
11 }
12
13 public static List<object> GetPropertyValue(object info)
14 {
15 List<object> list = new List<object>();
16 if (info == null) return null;
17 Type t = info.GetType();
18 //IEnumerable<System.Reflection.PropertyInfo> property = from pi in t.GetProperties() where pi.Name.ToLower() == field.ToLower() select pi;
19 IEnumerable<System.Reflection.PropertyInfo> property = t.GetProperties();
20 foreach (PropertyInfo prpInfo in property)
21 {
22 string sProName= prpInfo.Name;
23 object obj= prpInfo.GetValue(info, null);
24 MessageBox.Show(sProName);
25 list.Add(obj);
26 }
27 return list;
28 }
2.C#迭代器
3.IEnumerable接口
参考文献:
http://www.cnblogs.com/zoupeiyang/archive/2010/04/08/1707472.html
作者:太一吾鱼水
文章未经说明均属原创,学习笔记可能有大段的引用,一般会注明参考文献。
欢迎大家留言交流,转载请注明出处。