我正在尝试通过类使用PropertyInfo进行交互并从中创建数据表。但是它不返回任何值。我有点难过;
public class thetransactions
{
public string FirstName;
public string Surname;
public string PreviousOwner;
public string NewOwner;
public string postcode;
public string[] FileName;
}
然后用这段代码做腿部工作;
theTransactions[] thetransactions = new theTransactions[10];
thetransactions[0] = JsonConvert.DeserializeObject<theTransactions>(mydatastring);
PropertyInfo[] properties = thetransactions.GetType().GetElementType().GetProperties();
DataTable sampletable = new DataTable();
DataColumn dc = null;
foreach (PropertyInfo pi in properties)
{
dc = new DataColumn();
dc.ColumnName = pi.Name;
dc.DataType = pi.PropertyType;
sampletable.Columns.Add(dc);
}
答案 0 :(得分:2)
问题是您在thetransactions
类中定义普通变量而不是属性:
public class thetransactions
{
public string FirstName{get;set;}
public string Surname{get;set;}
public string PreviousOwner{get;set;}
public string NewOwner{get;set;}
public string postcode{get;set;}
public string[] FileName{get;set;}
}