Ejemplo n.º 1
0
        private static string jsonWriterToString(Action <JsonWriter> serializer)
        {
            StringBuilder resultBuilder = new StringBuilder();

            // [WMR 20160421] Explicit disposal

            //StringWriter sw = new StringWriter(resultBuilder);
            //JsonWriter jw = new BetterDecimalJsonTextWriter(sw);
            //serializer(jw);
            //jw.Flush();
            //jw.Close();
            //return resultBuilder.ToString();

            using (StringWriter sw = new StringWriter(resultBuilder))
                using (JsonWriter jw = SerializationUtil.CreateJsonTextWriter(sw))
                {
                    // [WMR 20160421] serializer action now calls Flush before disposing
                    serializer(jw);
                    // jw.Flush();
                    // jw.Close();
                    return(resultBuilder.ToString());
                }
        }
Ejemplo n.º 2
0
        private static byte[] jsonWriterToBytes(Action <JsonWriter> serializer)
        {
            // [WMR 20160421] Explicit disposal

            //MemoryStream stream = new MemoryStream();
            //var sw = new StreamWriter(stream, new UTF8Encoding(false));
            //JsonWriter jw = new BetterDecimalJsonTextWriter(sw);
            //serializer(jw);
            //jw.Flush();
            //return stream.ToArray();

            using (MemoryStream stream = new MemoryStream())
            {
                using (var sw = new StreamWriter(stream, new UTF8Encoding(false)))
                    using (JsonWriter jw = SerializationUtil.CreateJsonTextWriter(sw))
                    {
                        // [WMR 20160421] serializer action now calls Flush before disposing
                        serializer(jw);
                        // jw.Flush();
                        return(stream.ToArray());
                    }
            }
        }