[英]Serialize xmls element attributes to properties of child object
我下面的xml元素:
<point X="-1368.087158" Y="-918.482910" Z="156.191040" nX="0.241530" nY="-0.945819" nZ="0.217001"/>
和以下對象結構:
public class Point
{
[XmlAttribute("X")]
public float X { get; set; }
[XmlAttribute("Y")]
public float Y { get; set; }
[XmlAttribute("Z")]
public float Z { get; set; }
}
public class Vertex: Point
{
[Xml...]
public Point Normal { get; set; }
}
如何序列化nX / nY / nZ?
過去,當遇到類似這樣的問題時,我會添加僅用於序列化的額外屬性。 因此,在您的情況下,您的Vertex類可能如下所示:
public class Vertex : Point
{
[XmlIgnore]
public Point Normal { get; set; }
[XmlAttribute]
public float nX
{
get { return Normal.X; }
set { Normal.X = value; }
}
//etc
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.