获取对象属性列表

 
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 ); } } }

你可能感兴趣的:(对象)