using System.Xml.Serialization;
public static void Main()
Address = new FlatAddress
var serializer = new XmlSerializer(typeof(House));
serializer.Serialize(Console.Out, house);
public sealed class House
public FlatAddress Address { get; set; }
public sealed class FlatAddress : IXmlSerializable
public string Street { set; get; }
public string HouseNo { set; get; }
public string State { set; get; }
public XmlSchema GetSchema()
public void ReadXml(XmlReader reader)
this.Street = reader.ReadContentAsString();
this.HouseNo = reader.ReadContentAsString();
this.State = reader.ReadContentAsString();
public void WriteXml(XmlWriter writer)
writer.WriteElementString(nameof(Street), this.Street);
var houseNoXml = new XElement(nameof(HouseNo), this.HouseNo);
writer.WriteRaw(houseNoXml.ToString());
var stateXml = new XElement(nameof(State), this.State);
writer.WriteRaw(stateXml.ToString());