using System;
using System.IO;
using System.Runtime.Serialization;
using System.Xml;
namespace Zuga.net
{
[DataContract]
public class President
{
[DataMember] public int Number { get; set; }
[DataMember] public string First { get; set; }
[DataMember] public string Last { get; set; }
[DataMember] public int Year { get; set; }
}
class Program
{
static void Main(string[] args)
{
var president = new President()
{
Number = 1,
First = "George",
Last = "Washington",
Year = 1789
};
var serializer = new DataContractSerializer(typeof(President));
var path = "president.xml";
using (var fs = new FileStream(path, FileMode.Create))
{
var writerSettings = new XmlWriterSettings()
{
Indent = true,
IndentChars = " "
};
using (var writer = XmlWriter.Create(fs, writerSettings))
{
serializer.WriteObject(writer, president);
}
}
}
}
}