public static void SerializeInventory() { var product = new Product { ProductID = 100, ProductName = "Product Thing", SupplierID = 10 }; var book = new BookProduct { ProductID = 101, ProductName = "How To Use Your New Product Thing", SupplierID = 10, ISBN = "1234567890" }; Product[] products = { product, book }; var inventory = new Inventory { InventoryItems = products }; using (FileStream stream = File.Create(InventoryFileName)) { var serializer = new XmlSerializer(typeof(Inventory), GetInventoryXmlAttributes()); serializer.Serialize(stream, inventory); } }
public static void SerializeProduct() { //new products object var product = new Product { ProductID = 200, CategoryID = 100, Discontinued = false, ProductName = "Serialize Objects", QuantityPerUnit = "6", ReorderLevel = 1, SupplierID = 1, UnitPrice = 1000, UnitsInStock = 10, UnitsOnOrder = 0 }; FileStream stream = File.OpenWrite(ProductFileName); using (TextWriter writer = new StreamWriter(stream)) { XmlSerializer serializer = new XmlSerializer(typeof(Product)); serializer.Serialize(writer, product); } }