I am converting from Datatable to List by using Datatable Extensions. Here when i am trying to add a row to a normal List property its working fine. But when i use a list with in a list i am facing problem. i am not able to set the value in property.
private static T CreateItemFromRow<T>(DataRow row, IList<PropertyInfo> properties) where T : new()
{
T item = new T();
foreach (var property in properties)
{
if (property.Name.Equals("ProductSpec"))
{
Type t = property.GetType();
// i am getting error when i am trying to do this
property.SetValue(item, ProductSpecIteration(property, row), null);
}
if (row.Table.Columns.Contains(property.Name))
{
property.SetValue(item, row[property.Name] == DBNull.Value?"":row[property.Name], null);
}
}
return item;
}
private static ProductSpec ProductSpecIteration(PropertyInfo property, DataRow row)
{
ProductSpec lstProductSpec = new ProductSpec();
lstProductSpec.product_specs_id = Convert.ToInt64(row["product_specs_id"]);
return lstProductSpec;
}
I am not able to generically do this. But even i am not able to add this in this extensions? Could any one help me out from this situations