static void Serialize<T>(T instance , string fileName) { using(XmlWriter writer = new XmlWriter(filename , Encoding.UTF8)) { XmlSerializer serializer = new XmlSerializer(typeof(T)); serializer.Serialize(writer , instance); } } Serialize<Order>(order , "order.xml");