Beispiel #1
0
        /// <summary>
        /// Deserialize a text format to object type T
        /// </summary>
        /// <param name="text">Text input</param>
        /// <param name="scalarConverter"></param>
        /// <typeparam name="T">Type of object to deserialize to</typeparam>
        /// <returns>Deserialized object</returns>
        public T Deserialize <T>(string text, IScalarConverter scalarConverter = null)
        {
            var reader = new UserTextReader(text);

            reader.MoveNext();
            return((T)IonSerializationPrivate.Deserialize(reader, typeof(T), scalarConverter));
        }
Beispiel #2
0
        /// <summary>
        /// Deserialize a text format to object type T
        /// </summary>
        /// <param name="text">Text input</param>
        /// <typeparam name="T">Type of object to deserialize to</typeparam>
        /// <returns>Deserialized object</returns>
        public T Deserialize <T>(string text)
        {
            var reader = new UserTextReader(text);

            reader.MoveNext();
            return((T)IonSerializationPrivate.Deserialize(reader, typeof(T)));
        }
Beispiel #3
0
 /// <summary>
 /// Deserialize a binary format to object type T
 /// </summary>
 /// <param name="binary">Binary input</param>
 /// <param name="scalarConverter"></param>
 /// <typeparam name="T">Type of object to deserialize to</typeparam>
 /// <returns>Deserialized object</returns>
 public T Deserialize <T>(byte[] binary, IScalarConverter scalarConverter = null)
 {
     using (var stream = new MemoryStream(binary))
     {
         var reader = new UserBinaryReader(stream, scalarConverter);
         reader.MoveNext();
         return((T)IonSerializationPrivate.Deserialize(reader, typeof(T), scalarConverter));
     }
 }
Beispiel #4
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());
     }
 }
 /// <summary>
 /// Deserialize a binary format to object type T
 /// </summary>
 /// <param name="binary">Binary input</param>
 /// <typeparam name="T">Type of object to deserialize to</typeparam>
 /// <returns>Deserialized object</returns>
 public T Deserialize <T>(byte[] binary)
 {
     using (var stream = new MemoryStream(binary))
     {
         var reader = new UserBinaryReader(stream);
         reader.MoveNext();
         return((T)IonSerializationPrivate.Deserialize(reader, typeof(T)));
     }
 }
Beispiel #6
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();
            }
        }
Beispiel #7
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());
            }
        }
Beispiel #8
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);
        }