public DataContractOrder(Guid id, DateTime date, DataContractProduct product, int quantity)
 {
     OrderID = id;
     OrderDate = date;
     Product = product;
     Quantity = quantity;
 }
Exemple #2
0
        static void SerializeViaDataContractSerializer()
        {
            DataContractProduct product = new DataContractProduct(Guid.NewGuid(), "Dell PC", "Xiamen FuJian", 4500);
            DataContractOrder order = new DataContractOrder();
            order.OrderID = Guid.NewGuid();
            order.Product = product;
            order.Quantity = 300;
            order.OrderDate = DateTime.Now;

            string fileName = _basePath + "Order.DataContractSerializer.xml";
            using (FileStream fs = new FileStream(fileName, FileMode.Create))
            {
                DataContractSerializer serializer = new DataContractSerializer(typeof(DataContractOrder));
                using (XmlDictionaryWriter writer = XmlDictionaryWriter.CreateTextWriter(fs))
                {
                    serializer.WriteObject(writer, order);
                }
            }
            Process.Start(fileName);
        }