目前,我有一个示例代码,其中包含一个类似于以下内容的类:
public partial class PositionData : object, System.Runtime.Serialization.IExtensibleDataObject
{
private System.Runtime.Serialization.ExtensionDataObject extensionDataField;
private string BCRSideField;
private string ConveyorField;
private string LineField;
private string OriginField;
private string SubConveyorField;
public System.Runtime.Serialization.ExtensionDataObject ExtensionData
{
get
{
return this.extensionDataField;
}
set
{
this.extensionDataField = value;
}
}
[System.Runtime.Serialization.DataMemberAttribute(IsRequired=true)]
public string BCRSide
{
get
{
return this.BCRSideField;
}
set
{
this.BCRSideField = value;
}
}
[System.Runtime.Serialization.DataMemberAttribute(IsRequired=true)]
public string Conveyor
{
get
{
return this.ConveyorField;
}
set
{
this.ConveyorField = value;
}
}
[System.Runtime.Serialization.DataMemberAttribute(IsRequired=true)]
public string Line
{
get
{
return this.LineField;
}
set
{
this.LineField = value;
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public string Origin
{
get
{
return this.OriginField;
}
set
{
this.OriginField = value;
}
}
[System.Runtime.Serialization.DataMemberAttribute(IsRequired=true)]
public string SubConveyor
{
get
{
return this.SubConveyorField;
}
set
{
this.SubConveyorField = value;
}
}
}
在运行时期间,将创建此类型的对象,并填充属性 ExtensionDataField 。但是我如何访问该对象的值?
ExtensionDataObject 的结构在运行时如下:
我尝试了以下操作,但是没有机会访问值“ M6 \ M6_SC2_1” :
var props = a.GetType().GetProperties(BindingFlags.NonPublic | BindingFlags.Instance);
foreach (var prop in props)
{
var propertieValue = prop.GetValue(data.Position.ExtensionData, null);
var subProps = propertieValue.GetType().GetProperties(BindingFlags.NonPublic | BindingFlags.Instance);
foreach (var subprop in subProps)
{
var subPropertieValue = prop.GetValue(data.Position.ExtensionData, null);
}
}