В настоящее время я работаю над перестройкой приложения WebForms до MVC. Часть этого преобразования требует отображения DataSets и DataTables в объекты. Метод, который я использую для достижения sh:
public static List<T> DataTableToEntityList<T>(DataTable sourceDataTable, params PropertyMapper[] propertyMappings) where T : class, new()
{
List<T> entityList = new List<T>();
if (sourceDataTable != null)
{
// Get all properties of the Type T
PropertyInfo[] entityProperties = typeof(T).GetProperties();
foreach (DataRow dr in sourceDataTable.Rows)
{
// Create Instance of the Type T
T entity = new T();
PopulateEntityClass<T>(entity, dr, entityProperties, propertyMappings);
entityList.Add(entity);
}
}
return entityList;
}
Основная программа:
public static void Main(string[] args)
{
Program program = new Program();
DataTable dt = program.createData();
List<superadminAction> list = Helper.DataMappingHelper.DataTableToEntityList<superadminAction>(dt, null);
foreach(superadminAction action in list)
{
if (action.Title != null)
Console.WriteLine(action.Title);
else
Console.WriteLine("null values");
}
Console.ReadLine();
}
Объект, в который я преобразую:
public class superadminAction
{
public int SuperAdminActionCounter;
public string Procedure, Title, Description, TemplateDescription;
}
}
Я не могу понять, почему я не могу получить доступ к свойствам в функции Main (...) .
Любые идеи будут высоко ценится.