using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml.Serialization;
class Program
{
static void Main(string[] args)
{
//OutputSerialized(new Outer() { Inner = new Inner() });
//OutputSerialized(new OuterCustom() { Inner = new Inner() });
OutputSerialized(
new Root()
{
Outer = new Outer() { Inner = new Inner() },
OuterCustom = new OuterCustom() { Inner = new Inner() }
});
}
static void OutputSerialized<T>(T t)
{
var sb = new StringBuilder();
using (var textwriter = new StringWriter(sb))
new XmlSerializer(typeof(T)).Serialize(textwriter, t);
Console.WriteLine(sb.ToString());
}
}
[Serializable]
public class Root
{
public Outer Outer { get; set; }
public OuterCustom OuterCustom { get; set; }
}
[Serializable] public class Inner { }
[Serializable] public class Outer { public Inner Inner { get; set; } }
public class OuterCustom : IXmlSerializable
{
public Inner Inner;
public void WriteXml(System.Xml.XmlWriter writer)
{
writer.WriteAttributeString(
"xmlns", "xsi", null, "http://w...content-available-to-author-only...3.org/2001/XMLSchema-instance");
writer.WriteAttributeString(
"xmlns", "xsd", null, "http://w...content-available-to-author-only...3.org/2001/XMLSchema");
writer.WriteStartElement("Inner");
new XmlSerializer(typeof(Inner)).Serialize(writer, Inner);
writer.WriteEndElement();
}
public System.Xml.Schema.XmlSchema GetSchema() { return null; }
public void ReadXml(System.Xml.XmlReader reader) { /**/ }
}