1
當有基類連載的性質我有幾個屬性基類:序列化派生類
// must include any derived classes here as known types or else they will throw errors on serialization
[KnownType(typeof(CollaborationEventMeasureDistance))]
[DataContract]
public partial class CollaborationEvent
{
public bool HasBeenTransported { get; set; }
public Guid MessageBoxGuid { get; set; }
public CollaborationEvent()
{
HasBeenTransported = false;
}
}
而且派生類中有自己的一些屬性:
public class CollaborationEventMeasureDistance : CollaborationEvent
{
public Geometry Geometry { get; set; }
}
當我序列化派生類,其所有屬性都被序列化,但它從基類繼承的屬性不是:
<CollaborationEvent i:type="CollaborationEventMeasureDistance">
<Geometry xmlns:d4p1="http://schemas.datacontract.org/2004/07/ESRI.ArcGIS.Client.Geometry"
i:type="d4p1:Polyline">
<d4p1:spatialReference>
<d4p1:wkid>26910</d4p1:wkid>
</d4p1:spatialReference>
<d4p1:paths>
<d4p1:points>
<d4p1:point>
<d4p1:spatialReference>
<d4p1:wkid>26910</d4p1:wkid>
</d4p1:spatialReference>
<d4p1:x>460892.23924271885</d4p1:x>
<d4p1:y>5367682.5572773879</d4p1:y>
</d4p1:point>
<d4p1:point>
<d4p1:spatialReference i:nil="true" />
<d4p1:x>461001.35841108358</d4p1:x>
<d4p1:y>5367648.5755294543</d4p1:y>
</d4p1:point>
</d4p1:points>
</d4p1:paths>
</Geometry>
</CollaborationEvent>
任何人都可以指出我做錯了什麼?
我希望我的XML看起來更像:
<CollaborationEvent i:type="CollaborationEventMeasureDistance">
<HasBeenTransported>True</HasBeenTransported>
<MessageBoxGuid>blah</MessageBoxGuid>
<Geometry xmlns:d4p1="http://schemas.datacontract.org/2004/07/ESRI.ArcGIS.Client.Geometry"
i:type="d4p1:Polyline">
<d4p1:spatialReference>
<d4p1:wkid>26910</d4p1:wkid>
</d4p1:spatialReference>
<d4p1:paths>
<d4p1:points>
<d4p1:point>
<d4p1:spatialReference>
<d4p1:wkid>26910</d4p1:wkid>
</d4p1:spatialReference>
<d4p1:x>460892.23924271885</d4p1:x>
<d4p1:y>5367682.5572773879</d4p1:y>
</d4p1:point>
<d4p1:point>
<d4p1:spatialReference i:nil="true" />
<d4p1:x>461001.35841108358</d4p1:x>
<d4p1:y>5367648.5755294543</d4p1:y>
</d4p1:point>
</d4p1:points>
</d4p1:paths>
</Geometry>
</CollaborationEvent>
感謝
他們是定在的時候序列化? –
我們可以看到你的序列化代碼嗎? –