获取对象属性列表

 
C# code

public void ff(Object objInit, Object[] obj, string[] items) { List<string> itemList = new List<string>(items); foreach( PropertyInfo pi in objInit.GetType().GetProperties()) { int idx = itemList.IndexOf(pi.Name); if (idx >= 0) { pi.SetValue(objInit, obj[idx], null); } } }

C# code
public void ff(Object objInit, Object[] obj, string[] items) { for (int i = 0; i < obj.Length; i++) { foreach (MemberInfo mi in objInit.GetType().GetMember(items[i])) { objInit.GetType().GetProperty(mi.Name).SetValue(objInit, obj[i],null); } } }
posted @ 2010-04-08 12:28  清风寻梦  阅读(394)  评论(0编辑  收藏  举报