111,130
社区成员
发帖
与我相关
我的任务
分享
public static IList FillDataList(object obj, System.Data.IDataReader reader, Hashtable columnTable)
{
ArrayList list = new ArrayList();
string value;
string columnName = string.Empty;
while (reader.Read())
{
foreach (PropertyInfo property in obj.GetType().GetProperties())
{
columnName = columnTable[property.Name].ToString();
value = reader[columnName].ToString();
if (value != "")
{
property.SetValue(obj, Convert.ChangeType(value, property.PropertyType), null);
}
}
list.Add(CloneObjectobj(obj)); //改这里
}
return list;
}
/// <summary>
/// 克隆对象
/// </summary>
/// <param name="obj">obj必须能够序列化</param>
/// <returns></returns>
private object CloneObject(object obj)
{
MemoryStream ms = new MemoryStream();
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(ms, obj);
ms.Position = 0;
Object ClonedObject = formatter.Deserialize(ms);
ms.Close();
return ClonedObject;
}
public static IList FillDataList(object obj, System.Data.IDataReader reader, Hashtable columnTable)
{
ArrayList list = new ArrayList();
string value;
string columnName = string.Empty;
while (reader.Read())
{
foreach (PropertyInfo property in obj.GetType().GetProperties())
{
columnName = columnTable[property.Name].ToString();
value = reader[columnName].ToString();
if (value != "")
{
property.SetValue(obj, Convert.ChangeType(value, property.PropertyType), null);
}
}
list.Add(obj.Clone()); //改这里
}
return list;
}