Пример #1
0
        public void XmlDeSerialization()
        {
            string xmlFluteData = "<?xml version=\"1.0\" encoding=\"utf-8\"?><Flute xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><FluteBrand>JUPITER</FluteBrand><Material>STEEL</Material><FluteType>CLASSIC</FluteType><InstrumentName>The flute of the golden king</InstrumentName><IsAntiquity>false</IsAntiquity><InstrumentGroup>WOODWINDS</InstrumentGroup><InstrumentValue>2000</InstrumentValue></Flute>";

            using (MemoryStream stream = new MemoryStream(new UTF8Encoding().GetBytes(xmlFluteData)))
            {
                using (new XmlTextWriter(stream, new UTF8Encoding(false)))
                {
                    Flute fl = (Flute) new XmlSerializer(typeof(Flute)).Deserialize(stream);
                    Assert.Equal <int>(fl.CompareTo(new Flute()
                    {
                        InstrumentName = "The flute of the golden king", InstrumentValue = 2000
                    }), 0);
                }
            }
        }