Ejemplo n.º 1
0
 public JsonWriter(Stream stream, FormattingData.Encoding encoding, bool prettyPrint = false)
 {
     _wroteListItem = false;
     _prettyPrint = prettyPrint;
     _indent = 0;
     _formatter = new StreamFormatter(stream, encoding == FormattingData.Encoding.Utf16 ? FormattingData.InvariantUtf16 : FormattingData.InvariantUtf8);
 }
Ejemplo n.º 2
0
 public JsonWriter(Stream stream, FormattingData.Encoding encoding, bool prettyPrint = false)
 {
     _wroteListItem = false;
     _prettyPrint = prettyPrint;
     _indent = 0;
     _pool = new ManagedBufferPool<byte>(2048);
     _formatter = new StreamFormatter(stream, encoding == FormattingData.Encoding.Utf16 ? FormattingData.InvariantUtf16 : FormattingData.InvariantUtf8, _pool);
 }
 public void CustomTypeToStreamUtf8()
 {
     byte[] buffer = new byte[1024];
     MemoryStream stream = new MemoryStream(buffer);
     var writer = new StreamFormatter(stream, FormattingData.InvariantUtf8);
     writer.Append(new Age(56));
     writer.Append(new Age(14, inMonths: true));
     var writtenText = Encoding.UTF8.GetString(buffer, 0, (int)stream.Position);
     Assert.Equal(writtenText, "56y14m");
 }
Ejemplo n.º 4
0
        public void CustomTypeToStreamUtf16()
        {
            byte[] buffer = new byte[1024];
            MemoryStream stream = new MemoryStream(buffer);
            using(var writer = new StreamFormatter(stream, pool)) {
                writer.Append(new Age(56));
                writer.Append(new Age(14, inMonths: true));

                var writtenText = Encoding.Unicode.GetString(buffer, 0, (int)stream.Position);
                Assert.Equal(writtenText, "56y14m");
            }
        }