标签:default 泛型 void efi def bin new t bind lis
public static IEnumerable<T> Parse<T>(IEnumerable<DataRow> rows) where T : class, new()
{
if (rows == null || Enumerable.FirstOrDefault<DataRow>(rows) == null)
return (IEnumerable<T>) new T[0];
PropertyInfo[] properties = typeof (T).GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.SetProperty);
List<T> list = new List<T>();
foreach (DataRow row in rows)
{
T instance = Activator.CreateInstance<T>();
DbHelper.Parse((object) instance, (IEnumerable<PropertyInfo>) properties, row);
list.Add(instance);
}
return (IEnumerable<T>) list;
}
private static void Parse(object obj, IEnumerable<PropertyInfo> properties, DataRow row)
{
foreach (PropertyInfo propertyInfo in properties)
{
if (DataRowExtension.HasValue(row, propertyInfo.Name))
{
try
{
propertyInfo.SetValue(obj, DbHelper.ConvertType(CultureInfo.CurrentCulture, row[propertyInfo.Name], propertyInfo.PropertyType), (object[]) null);
}
}
catch{ }
}
}
标签:default 泛型 void efi def bin new t bind lis
原文地址:http://www.cnblogs.com/Lulus/p/7905328.html