XML serialization - bypass container class?
I am trying to serialize an object in a particular manner. The main class
has a container class that holds some attributes, but really these
attributes should be on the main class, from the point of view of the
schema. Is there a way to bypass the container class and treat the
properties on the container class as properties on the main class, for the
purposes of serialization?
I am trying to create XML along the lines of:
<Main foo="3" bar="something">
<Others>etc</Others>
</Main>
from this code:
[System.Xml.Serialization.XmlRootAttribute("Main", Namespace = "")]
public class MainObject
{
public HelperContainer { get; set; }
public string Others { get; set; }
}
public class HelperContainer
{
[System.Xml.Serialization.XmlAttributeAttribute(AttributeName = "foo")]
public int Foo { get; set; }
[System.Xml.Serialization.XmlAttributeAttribute(AttributeName = "bar")]
public string Bar { get; set; }
}
No comments:
Post a Comment