More to come.
The User class decorated with custom attributes
class User
{
[XmlAttribute("name")] string Name { get; set; }
[XmlIgnore] string Password { get; set; }
[XmlElement("domain", 1)] string Domain { get; set; }
[XmlAttribute("dept")] string Department { get; set; }
[XmlElement("background", 2)] string Background { get; set; }
}
is actually equivalent to using the following custom xml class map
class UserMap : XmlClassMap<User>
{
Map(x => x.Name).UsingName("name").AsAttribute();
Map(x => x.Domain).UsingName("domain").OrderedAs(1);
Map(x => x.Department).UsingName("dept");
Map(x => x.Background).UsingName("background").OrderedAs(2);
}
Using the custom map is quite simple and demonstrated below
var serializer = new Serializer();
serializer.RegisterClassMap<UserMap>();
Once you have registered the map your serializer will use it to determine layout from that point forward.