Пример #1
0
        public void TestRoundTrip()
        {
            object inObject = true;
            object outObject;

            string s;

            using (Stream output = new MemoryStream())
            {
                IWriter <object> w = TransitFactory.Writer <object>(TransitFactory.Format.JsonVerbose, output);
                w.Write(inObject);

                output.Position = 0;
                var sr = new StreamReader(output);
                s = sr.ReadToEnd();
            }

            byte[] buffer = Encoding.ASCII.GetBytes(s);
            using (Stream input = new MemoryStream(buffer))
            {
                IReader reader = TransitFactory.Reader(TransitFactory.Format.Json, input);
                outObject = reader.Read <object>();
            }

            Assert.IsTrue(IsEqual(inObject, outObject));
        }
Пример #2
0
        public string Write(object obj, TransitFactory.Format format, IDictionary <Type, IWriteHandler> customHandlers)
        {
            using (Stream output = new MemoryStream())
            {
                IWriter <object> w = TransitFactory.Writer <object>(format, output, customHandlers);
                w.Write(obj);

                output.Position = 0;
                var sr = new StreamReader(output);
                return(sr.ReadToEnd());
            }
        }