2010-07-16 135 views
0

我下面的XML元素的子對象的屬性:序列化個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 /新西蘭?

回答

0

在過去,當用這樣的東西命中時,我會添加額外的屬性,只用於序列化。所以在你的情況下,你的頂點類可能看起來像這樣:

public class Vertex : Point 
{ 
    [XmlIgnore] 
    public Point Normal { get; set; } 

    [XmlAttribute] 
    public float nX 
    { 
     get { return Normal.X; } 
     set { Normal.X = value; } 
    } 

    //etc 
} 
+0

謝謝。所以你的意思是沒有更好的解決方案呢?我只是試圖避免使用這種方法。 – David 2010-07-16 14:57:52

+0

我不知道另一種方式來做到這一點,這並不意味着不存在。 – 2010-07-19 14:25:54