Beispiel #1
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()));
         }
 }
Beispiel #2
0
 private static TContainer Deserialize <TContainer>(SerializedObjectReader reader)
     where TContainer : new()
 {
     using (reader)
     {
         var target = new TContainer();
         PropertyContainer.Transfer(target, reader.ReadObject());
         return(target);
     }
 }
Beispiel #3
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);
        }