hashtable转modelList,modelist是T,怎么将hashtabel组装成一个对象啊<model>啊求大神!
已知有modellist转hashtable
源码如下;
public static Hashtable ModelToHashtable<T>(T model)
{
Hashtable hashtable = new Hashtable();
T obj = Activator.CreateInstance<T>();
Type type = obj.GetType();
PropertyInfo[] pis = type.GetProperties();
for (int i = 0; i< pis.Length; i++)
{
hashtable[pis[j].Name.ToString()] = pis[j].GetValue(model, null);
}
return hashtable;
}
求反过来!
------解决方案--------------------
public static T HashtableToModel<T>(Hashtable ht)
{
T obj = Activator.CreateInstance<T>();
foreach (string s in ht.Keys)
{
T.GetType().GetPropertie(s).SetValue(obj, ht[s], null);
}
return obj;
}