Пример #1
0
        static void Main()
        {
            var config = new Config
            {
                Variant = "Simple",
                Enabled = true,
                Urls    = { "http://example.com", "http://www.example.com" }
            };

            var xmlString = new StringBuilder();
            var xmlWriter = new SimpleXmlWriter(XmlWriter.Create(xmlString, new XmlWriterSettings
            {
                OmitXmlDeclaration = true,
                Indent             = true
            }));

            Serialize.To(xmlWriter, config);
            xmlWriter.Flush();
            Console.WriteLine(xmlString);

            const string configString =
                @"<Config>
  <Urls>
    <Item>http://example.com</Item>
  </Urls>
  <Enabled>false</Enabled>
  <Variant>Complex</Variant>
</Config>";

            var reader = new SimpleXmlReader(XmlReader.Create(new StringReader(configString)));

            config = Deserialize <Config> .From(reader);

            Debug.Assert(config.Enabled == false);
        }
Пример #2
0
    void Awake()
    {
        Assertion.AssertNotNull(sampleXml, "sampleXml");

        SimpleXmlReader reader = new SimpleXmlReader();

        reader.PrintXML(reader.Read(sampleXml.text), 0);
    }
        public Task <TValue> Deserialize <TValue>(byte[] data)
        {
            var sourceStream = new MemoryStream(data);

            var reader = new SimpleXmlReader(sourceStream);

            return(Task.FromResult(global::Bond.Deserialize <TValue> .From(reader)));
        }
Пример #4
0
        private void Parse()
        {
            SimpleXmlReader reader = new SimpleXmlReader();
            SimpleXmlNode   root   = reader.Read(xmlFile.text).FindFirstNodeInChildren("Variables");

            for (int i = 0; i < root.Children.Count; ++i)
            {
                SimpleXmlNode child = root.Children[i];
                if (ENTRY.Equals(child.TagName))
                {
                    string key   = child.GetAttribute(KEY);
                    string value = child.GetAttribute(VALUE);
                    this.varMap[key] = value;
                }
            }
        }
Пример #5
0
        void RoundtripObjectBuffer <T>(T obj)
        {
            // SimpleBinary
            {
                var output = new OutputBuffer();
                var writer = new SimpleBinaryWriter <OutputBuffer>(output);
                Serialize.To(writer, obj);

                var input  = new InputBuffer(output.Data);
                var reader = new SimpleBinaryReader <InputBuffer>(input);
                T   obj2   = Deserialize <T> .From(reader);

                Assert.True(Comparer.Equal <T>(obj, obj2));
            }

            // CompactBinary
            {
                var output = new OutputBuffer();
                var writer = new CompactBinaryWriter <OutputBuffer>(output);
                Serialize.To(writer, obj);

                var input  = new InputBuffer(output.Data);
                var reader = new CompactBinaryReader <InputBuffer>(input);
                T   obj2   = new Deserializer <CompactBinaryReader <InputBuffer> >(typeof(T)).Deserialize <T>(reader);

                Assert.True(Comparer.Equal <T>(obj, obj2));
            }

            // SimpleXML
            {
                var xmlString = new StringBuilder();
                var xmlWriter = new SimpleXmlWriter(XmlWriter.Create(xmlString));

                Serialize.To(xmlWriter, obj);
                xmlWriter.Flush();

                var reader = new SimpleXmlReader(XmlReader.Create(new StringReader(xmlString.ToString())));
                T   obj2   = new Deserializer <SimpleXmlReader>(typeof(T)).Deserialize <T>(reader);

                Assert.True(Comparer.Equal <T>(obj, obj2));
            }
        }
Пример #6
0
        public void RountripFoo()
        {
            var sb  = new StringBuilder();
            var foo = new Foo {
                Value = 1
            };

            using (XmlWriter xmlWriter = XmlWriter.Create(sb))
            {
                var writer = new SimpleXmlWriter(xmlWriter);
                Serialize.To(writer, foo);
                writer.Flush();
            }
            var xml = sb.ToString();

            Console.Write(xml);
            using (var xmlReader = XmlReader.Create(new StringReader(xml)))
            {
                var reader       = new SimpleXmlReader(xmlReader);
                var roundtripped = Deserialize <Foo> .From(reader);

                Assert.AreEqual(foo.Value, roundtripped.Value);
            }
        }
Пример #7
0
        public static T DeserializeXml <T>(Stream stream)
        {
            var reader = new SimpleXmlReader(stream);

            return(Deserialize <T> .From(reader));
        }
Пример #8
0
        private static T ParseXml <T>(string xml) where T : new()
        {
            var reader = new SimpleXmlReader(XmlReader.Create(new StringReader(xml), xmlReaderSettings));

            return(Deserialize <T> .From(reader));
        }