B
Born2Achieve
Guest
Hi,
How can i make this static method as async. Basically this method will map the data reader property with class property.
public static List<T> ConvertList<T>(this DbDataReader dr) where T : new()
{
List<T> lstRet= null;
var Entity = typeof(T);
var PropDict = new Dictionary<string, PropertyInfo>();
try
{
if (dr != null && dr.HasRows)
{
lstRet= new List<T>();
var Props = Entity.GetProperties(BindingFlags.Instance | BindingFlags.Public);
PropDict = Props.ToDictionary(p => p.Name.ToUpper(), p => p);
while (dr.Read())
{
T newObject = new T();
for (int Index = 0; Index < dr.FieldCount; Index++)
{
if (PropDict.ContainsKey(dr.GetName(Index).ToUpper()))
{
var Info = PropDict[dr.GetName(Index).ToUpper()];
if ((Info != null) && Info.CanWrite)
{
var Val = dr.GetValue(Index);
Info.SetValue(newObject, (Val == DBNull.Value) ? null : Val, null);
}
}
}
lstRet.Add(newObject);
}
}
}
catch (Exception)
{
throw;
}
return lstRet;
}
i tried to add async key word in front of the List<T>. i but i am not sure where to use the await in the code. any help will be highly appreciated
loving dotnet
Continue reading...
How can i make this static method as async. Basically this method will map the data reader property with class property.
public static List<T> ConvertList<T>(this DbDataReader dr) where T : new()
{
List<T> lstRet= null;
var Entity = typeof(T);
var PropDict = new Dictionary<string, PropertyInfo>();
try
{
if (dr != null && dr.HasRows)
{
lstRet= new List<T>();
var Props = Entity.GetProperties(BindingFlags.Instance | BindingFlags.Public);
PropDict = Props.ToDictionary(p => p.Name.ToUpper(), p => p);
while (dr.Read())
{
T newObject = new T();
for (int Index = 0; Index < dr.FieldCount; Index++)
{
if (PropDict.ContainsKey(dr.GetName(Index).ToUpper()))
{
var Info = PropDict[dr.GetName(Index).ToUpper()];
if ((Info != null) && Info.CanWrite)
{
var Val = dr.GetValue(Index);
Info.SetValue(newObject, (Val == DBNull.Value) ? null : Val, null);
}
}
}
lstRet.Add(newObject);
}
}
}
catch (Exception)
{
throw;
}
return lstRet;
}
i tried to add async key word in front of the List<T>. i but i am not sure where to use the await in the code. any help will be highly appreciated
loving dotnet
Continue reading...