6
public static IList<T> ConvertTo<T>(DataTable table)
{
if (table == null)
{
return null;
}
List<DataRow> rows = new List<DataRow>();
foreach (DataRow row in table.Rows)
{
rows.Add(row);
}
return ConvertTo<T>(rows);
}
public static T ConvertItem<T>(DataTable table)
{
T obj = default(T);
if (table != null && table.Rows.Count > 0)
{
obj = CreateItem<T>(table.Rows[0]);
}
return obj;
}
public static T CreateItem<T>(DataRow row)
{
T obj = default(T);
if (row != null)
{
obj = Activator.CreateInstance<T>();
Type entityType = typeof(T);
PropertyInfo[] properties = entityType.GetProperties();
for (int i = 0; i < properties.Length; i++)
{
object[] customAttributes = properties[i].GetCustomAttributes(typeof(ColumnAttributes), false);
ColumnAttributes dataField = null;
if (null != customAttributes && customAttributes.Length > 0 && null != (dataField = customAttributes[0] as ColumnAttributes))
{
if (row.Table.Columns.Contains(dataField.FieldName) && !row[dataField.FieldName].GetType().FullName.Equals("System.DBNull"))
{
properties[i].SetValue(obj, row[dataField.FieldName], null);
}
}
}
}
return obj;
}
这就是我们现在唯一能想到的,就是我们必须做一些我们需要的东西垃圾收集我们自己?将DataTable转换为泛型列表?
想法?
为什么我们认为有可能是泄漏?:
我们越来越内存不足的错误。如果页面不需要业务逻辑来使用这种类型的转换,那么II6过程不会增长,但是当我们点击一个使用它的页面时,它会增长。
我们目前正在让蚂蚁探查器给我们更多的细节。
你有什么证据泄漏的? – 2009-02-13 09:32:21
准确的问题在哪里? – 2009-02-13 09:35:49