public XMLOrder(Guid id, DateTime date, XMLProduct product, int quantity) { this._orderID = id; this._orderDate = date; this._product = product; this._quantity = quantity; }
static void SerializeViaXMLSerializer() { XMLProduct product = new XMLProduct(Guid.NewGuid(), "Dell PC", "Xiamen FuJian", 4500); XMLOrder order = new XMLOrder(Guid.NewGuid(), DateTime.Today, product, 300); string fileName = _basePath + "Order.XmlSerializer.xml"; using (FileStream fs = new FileStream(fileName, FileMode.Create)) { XmlSerializer serializer = new XmlSerializer(typeof(XMLOrder)); using (XmlDictionaryWriter writer = XmlDictionaryWriter.CreateTextWriter(fs)) { serializer.Serialize(writer, order); } } Process.Start(fileName); }