views:

17

answers:

1

Hello,

I've following xml element:

<point X="-1368.087158" Y="-918.482910" Z="156.191040" nX="0.241530" nY="-0.945819" nZ="0.217001"/>

and following object structure:

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; }
}

How can I serialize nX/nY/nZ?

A: 

In the past when hit with something like this I would add extra properties that only are to be used for serialization. So in your case, your Vertex class might look like this:

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

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

    //etc
}
Jake Pearson
Thanks. So you mean there's no better solution for this? I just tried to avoid using that kind of approach.
David
I don't know of another way to do this, that doesn't mean one doesn't exist.
Jake Pearson