Exemplo n.º 1
0
 public string Serialize <T>(T obj, IonTextOptions options, IScalarWriter scalarWriter = null)
 {
     using (var sw = new StringWriter())
     {
         var writer = new IonTextWriter(sw, options);
         IonSerializationPrivate.WriteObject(writer, obj, scalarWriter);
         return(sw.ToString());
     }
 }
Exemplo n.º 2
0
        public void Serialize <T>(T obj, Stream stream, IScalarWriter scalarWriter = null)
        {
            if (!stream.CanWrite)
            {
                throw new ArgumentException("Stream must be writable", nameof(stream));
            }


            using (var binWriter = new ManagedBinaryWriter(stream, Symbols.EmptySymbolTablesArray))
            {
                IonSerializationPrivate.WriteObject(binWriter, obj, scalarWriter);
                binWriter.Flush();
            }
        }
Exemplo n.º 3
0
        public byte[] Serialize <T>(T obj, IScalarWriter scalarWriter = null)
        {
            using (var stream = new MemoryStream())
            {
                using (var binWriter = new ManagedBinaryWriter(stream, Symbols.EmptySymbolTablesArray))
                {
                    IonSerializationPrivate.WriteObject(binWriter, obj, scalarWriter);
                    binWriter.Flush();
                    binWriter.Finish();
                }

                return(stream.GetWrittenBuffer());
            }
        }
Exemplo n.º 4
0
        public Task SerializeAsync <T>(T obj, Stream stream, IonTextOptions options)
        {
            if (!stream.CanWrite)
            {
                throw new ArgumentException("Stream must be writable", nameof(stream));
            }

            using (var streamWriter = new StreamWriter(stream))
            {
                var writer = new IonTextWriter(streamWriter, options);
                IonSerializationPrivate.WriteObject(writer, obj, null);
            }

            return(Task.CompletedTask);
        }