質問

私は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);
}
.

役に立ちましたか?

解決

問題は、 ronomation 変数を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;}
}
.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top