利用泛型,把DataReader转换为List的,怎么报错
我用vs2005的,下面的代码是把DataReader转换为List的,但是编译时提示:
The type or namespace name 'BindingFieldAttribute' could not be found (are you missing a using directive or an assembly reference?)
怎么会出这个错误呢?
public static IList<T> FillList<T>(System.Data.IDataReader reader)
{
IList<T> lst = new List<T>();
while (reader.Read())
{
T RowInstance = Activator.CreateInstance<T>();
foreach (PropertyInfo Property in typeof(T).GetProperties())
{
foreach (BindingFieldAttribute FieldAttr in Property.GetCustomAttributes(typeof(BindingFieldAttribute), true))
{
try
{
int Ordinal = reader.GetOrdinal(FieldAttr.FieldName);
if (reader.GetValue(Ordinal) != DBNull.Value)
{
Property.SetValue(RowInstance, Convert.ChangeType(reader.GetValue(Ordinal), Property.PropertyType), null);
}
}
catch
{
break;
}
}
}
lst.Add(RowInstance);
}
return lst;
}