示例#1
0
 /// <summary>
 /// Deserializes the given stream and writes the data to the given container.
 /// </summary>
 /// <typeparam name="TContainer">The type to deserialize.</typeparam>
 /// <param name="stream">The stream to read from.</param>
 /// <param name="container">The container to deserialize data in to.</param>
 public static VisitResult DeserializeFromStream <TContainer>(Stream stream, ref TContainer container)
 {
     using (var reader = new SerializedObjectReader(stream))
     {
         return(Deserialize(reader, ref container));
     }
 }
示例#2
0
 /// <summary>
 /// Deserializes the given file path and writes the data to the given container.
 /// </summary>
 /// <param name="path">The file path to read from.</param>
 /// <param name="container">The container to deserialize data in to.</param>
 /// <typeparam name="TContainer">The type to deserialize.</typeparam>
 public static VisitResult DeserializeFromPath <TContainer>(string path, ref TContainer container)
 {
     using (var reader = new SerializedObjectReader(path))
     {
         return(Deserialize(reader, ref container));
     }
 }
示例#3
0
 /// <summary>
 /// Creates and returns an object from the given JSON string.
 /// </summary>
 /// <param name="json">JSON string to deserialize.</param>
 /// <returns>The created object.</returns>
 public static JsonObject DeserializeFromString(string json)
 {
     using (var memory = new MemoryStream(Encoding.UTF8.GetBytes(json)))
         using (var reader = new SerializedObjectReader(memory))
         {
             return(new JsonObject(reader.ReadObject()));
         }
 }
示例#4
0
 private static TContainer Deserialize <TContainer>(SerializedObjectReader reader)
     where TContainer : new()
 {
     using (reader)
     {
         var target = new TContainer();
         PropertyContainer.Transfer(target, reader.ReadObject());
         return(target);
     }
 }
示例#5
0
        /// <summary>
        /// Deserializes the given file path and returns a new instance of the container.
        /// </summary>
        /// <param name="path">The file path to read from.</param>
        /// <typeparam name="TContainer">The type to deserialize.</typeparam>
        /// <returns>A new instance of the container with based on the serialized data.</returns>
        public static TContainer DeserializeFromPath <TContainer>(string path)
            where TContainer : new()
        {
            var container = new TContainer();

            using (var reader = new SerializedObjectReader(path))
            {
                using (var result = Deserialize(reader, ref container))
                {
                    result.Throw();
                }
            }
            return(container);
        }
示例#6
0
        static VisitResult Deserialize <TContainer>(SerializedObjectReader reader, ref TContainer container)
        {
            var source = reader.ReadObject();
            var result = VisitResult.GetPooled();

            try
            {
                using (var construction = PropertyContainer.Construct(ref container, ref source, new PropertyContainerConstructOptions {
                    TypeIdentifierKey = JsonVisitor.Style.TypeInfoKey
                }))
                    result.TransferEvents(construction);

                using (var transfer = PropertyContainer.Transfer(ref container, ref source))
                    result.TransferEvents(transfer);
            }
            catch (Exception)
            {
                reader.Dispose();
                throw;
            }

            return(result);
        }