Example #1
0
 static void SerializeViaDataContractSerializer()
 {
     DataContractProduct product = new DataContractProduct(Guid.NewGuid(), "Dell PC", "Xiamen FuJian", 4500);
     DataContractOrder order = new DataContractOrder(Guid.NewGuid(), DateTime.Today, product, 300);
     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);
 }
Example #2
0
        static void SerializeViaDataContractSerializer()
        {
            DataContractProduct product = new DataContractProduct(Guid.NewGuid(), "Dell PC", "Xiamen FuJian", 4500);
            DataContractOrder   order   = new DataContractOrder(Guid.NewGuid(), DateTime.Today, product, 300);
            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);
        }
Example #3
0
        private static void DataContractToXmlSerialization()
        {
            var product = new DataContractProduct(Guid.NewGuid(), "productTestName", "china", 10.25);
            var order = new DataContractOrder(Guid.NewGuid(), DateTime.Now, product, 10);

            var baseDir = AppDomain.CurrentDomain.BaseDirectory;
            var fileName = "../xml.xml";
            var fullFileName = Path.Combine(baseDir, fileName);

            using (var stream = new FileStream(fullFileName, FileMode.Create)) {
                var serializationTool = new DataContractSerializer(typeof(XmlOrder));
                using (var writer = XmlDictionaryWriter.CreateTextWriter(stream)) {
                    serializationTool.WriteObject(writer, order);
                }
                Process.Start(fullFileName);
            }
        }