コード例 #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());
     }
 }
コード例 #2
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;
        }