typeof().GetFields 不显示 List<T>
typeof().GetFields doesnt show List<T>
我正在尝试查看我的 class,但我无法列出所有内容。
我有class:
public class Order
{
public string PO_NO { get; set; }
public string APPROVED_DATE { get; set; }
public string SPPLR_CONTACT { get; set; } //SPPLR_Mailbox
public string PO_REMARKS { get; set; }
public string PO_CREATION_DATE { get; set; }
public string SPPLR_CD { get; set; }
public string OWN_CD { get; set; }
public string LOCATION_CODE { get; set; }
public string LOCATION_ID { get; set; }
public string SHIPPING_TYPE { get; set; }
public string FREIGHT_TERMS { get; set; }
public string PO_STATUS { get; set; }
public string CONTACT_PERSON { get; set; }
public string CONTACT_PERSON_MAIL { get; set; }
public string CONTACT_PERSON_PHONE { get; set; }
public string ATTRIBUTE01 { get; set; }
public string ATTRIBUTE02 { get; set; }
public string ATTRIBUTE03 { get; set; }
public string ATTRIBUTE04 { get; set; }
public string ATTRIBUTE05 { get; set; }
public List<OrderDetails> OrderDetails = new List<OrderDetails>();
}
我正在尝试 "enumerate" 那样
FieldInfo[] fields = typeof(Order).GetFields(BindingFlags.NonPublic | BindingFlags.Instance);
foreach (var field in fields)
{
Debug.WriteLine(field.Name + "---" + field.FieldType);
}
得到这个输出:
<PO_NO>k__BackingField---System.String
<APPROVED_DATE>k__BackingField---System.String
<SPPLR_CONTACT>k__BackingField---System.String
<PO_REMARKS>k__BackingField---System.String
<PO_CREATION_DATE>k__BackingField---System.String
<SPPLR_CD>k__BackingField---System.String
<OWN_CD>k__BackingField---System.String
<LOCATION_CODE>k__BackingField---System.String
<LOCATION_ID>k__BackingField---System.String
<SHIPPING_TYPE>k__BackingField---System.String
<FREIGHT_TERMS>k__BackingField---System.String
<PO_STATUS>k__BackingField---System.String
<CONTACT_PERSON>k__BackingField---System.String
<CONTACT_PERSON_MAIL>k__BackingField---System.String
<CONTACT_PERSON_PHONE>k__BackingField---System.String
<ATTRIBUTE01>k__BackingField---System.String
<ATTRIBUTE02>k__BackingField---System.String
<ATTRIBUTE03>k__BackingField---System.String
<ATTRIBUTE04>k__BackingField---System.String
<ATTRIBUTE05>k__BackingField---System.String
列表丢失,出了什么问题,或者我该怎么做才能将其列出?
我正在尝试为 myslef 创建库,我可以将其挂在 class 上并生成整个 xml,但我无法进行动态结构,因为我是没有得到那个列表(子节点)
正如@thehenny 所说,BindingFlags 不正确。我刚刚添加了 BindingFlags.Public
所以代码来自:
FieldInfo[] fields = typeof(Order).GetFields(BindingFlags.NonPublic | BindingFlags.Instance );
foreach (var field in fields)
{
Debug.WriteLine(field.Name + "---" + field.FieldType);
}
收件人:
FieldInfo[] fields = typeof(Order).GetFields(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
foreach (var field in fields)
{
Debug.WriteLine(field.Name + "---" + field.FieldType);
}
我正在尝试查看我的 class,但我无法列出所有内容。
我有class:
public class Order
{
public string PO_NO { get; set; }
public string APPROVED_DATE { get; set; }
public string SPPLR_CONTACT { get; set; } //SPPLR_Mailbox
public string PO_REMARKS { get; set; }
public string PO_CREATION_DATE { get; set; }
public string SPPLR_CD { get; set; }
public string OWN_CD { get; set; }
public string LOCATION_CODE { get; set; }
public string LOCATION_ID { get; set; }
public string SHIPPING_TYPE { get; set; }
public string FREIGHT_TERMS { get; set; }
public string PO_STATUS { get; set; }
public string CONTACT_PERSON { get; set; }
public string CONTACT_PERSON_MAIL { get; set; }
public string CONTACT_PERSON_PHONE { get; set; }
public string ATTRIBUTE01 { get; set; }
public string ATTRIBUTE02 { get; set; }
public string ATTRIBUTE03 { get; set; }
public string ATTRIBUTE04 { get; set; }
public string ATTRIBUTE05 { get; set; }
public List<OrderDetails> OrderDetails = new List<OrderDetails>();
}
我正在尝试 "enumerate" 那样
FieldInfo[] fields = typeof(Order).GetFields(BindingFlags.NonPublic | BindingFlags.Instance);
foreach (var field in fields)
{
Debug.WriteLine(field.Name + "---" + field.FieldType);
}
得到这个输出:
<PO_NO>k__BackingField---System.String
<APPROVED_DATE>k__BackingField---System.String
<SPPLR_CONTACT>k__BackingField---System.String
<PO_REMARKS>k__BackingField---System.String
<PO_CREATION_DATE>k__BackingField---System.String
<SPPLR_CD>k__BackingField---System.String
<OWN_CD>k__BackingField---System.String
<LOCATION_CODE>k__BackingField---System.String
<LOCATION_ID>k__BackingField---System.String
<SHIPPING_TYPE>k__BackingField---System.String
<FREIGHT_TERMS>k__BackingField---System.String
<PO_STATUS>k__BackingField---System.String
<CONTACT_PERSON>k__BackingField---System.String
<CONTACT_PERSON_MAIL>k__BackingField---System.String
<CONTACT_PERSON_PHONE>k__BackingField---System.String
<ATTRIBUTE01>k__BackingField---System.String
<ATTRIBUTE02>k__BackingField---System.String
<ATTRIBUTE03>k__BackingField---System.String
<ATTRIBUTE04>k__BackingField---System.String
<ATTRIBUTE05>k__BackingField---System.String
列表丢失,出了什么问题,或者我该怎么做才能将其列出?
我正在尝试为 myslef 创建库,我可以将其挂在 class 上并生成整个 xml,但我无法进行动态结构,因为我是没有得到那个列表(子节点)
正如@thehenny 所说,BindingFlags 不正确。我刚刚添加了 BindingFlags.Public
所以代码来自:
FieldInfo[] fields = typeof(Order).GetFields(BindingFlags.NonPublic | BindingFlags.Instance );
foreach (var field in fields)
{
Debug.WriteLine(field.Name + "---" + field.FieldType);
}
收件人:
FieldInfo[] fields = typeof(Order).GetFields(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
foreach (var field in fields)
{
Debug.WriteLine(field.Name + "---" + field.FieldType);
}