Пример #1
0
 /// <summary>
 /// Sets the parent of supplied value to null if this
 /// node is the current parent.
 /// </summary>
 /// <param name="value"></param>
 protected void RemoveParent(IJsonStruct value)
 {
     if (ReferenceEquals(((JsonStruct)value)._parent, this))
     {
         ((JsonStruct)value)._parent = null;
     }
 }
Пример #2
0
 public Task WriteJsonStructAsync(IJsonStruct value, CancellationToken cancellationToken = default(CancellationToken))
 {
     if (value == null)
     {
         return(JsonTextWriter.WriteNullAsync(cancellationToken));
     }
     return(value.WriteAsync(this, cancellationToken));
 }
Пример #3
0
 /// <summary>
 /// Sets the parent of supplied structure to this object
 /// </summary>
 /// <param name="value"></param>
 protected void SetParent(IJsonStruct value)
 {
     if (value == null)
     {
         return;
     }
     ((JsonStruct)value)._parent = this;
 }
Пример #4
0
 /// <summary>
 /// Emits supplied value to the writer.
 /// </summary>
 /// <param name="value"></param>
 /// <param name="cancellationToken"></param>
 public Task WriteJsonStructAsync(IJsonStruct value, CancellationToken cancellationToken = default(CancellationToken))
 {
     if (value == null)
     {
         LastWrittenToken = WrittenToken.Null;
         return(TextWriter.WriteAsync("null"));
     }
     return(value.WriteAsync(this, cancellationToken));
 }
Пример #5
0
 public override double CreateType(IJsonStruct jsonStruct)
 {
     if (jsonStruct == null)
     {
         return(default(double));
     }
     else if (jsonStruct is IJsonFloat jf)
     {
         return(jf.Float);
     }
     throw new Exception($"Cannot convert {jsonStruct.GetType().FullName} to a double.");
 }
Пример #6
0
 public override bool CreateType(IJsonStruct jsonStruct)
 {
     if (jsonStruct == null)
     {
         return(default(bool));
     }
     else if (jsonStruct is IJsonBoolean jb)
     {
         return(jb.Boolean);
     }
     throw new Exception($"Cannot convert {jsonStruct.GetType().FullName} to a boolean.");
 }
Пример #7
0
 public override int CreateType(IJsonStruct jsonStruct)
 {
     if (jsonStruct == null)
     {
         return(default(int));
     }
     else if (jsonStruct is IJsonInteger js)
     {
         return((int)js.Integer);
     }
     throw new Exception($"Cannot convert {jsonStruct.GetType().FullName} to a string.");
 }
Пример #8
0
 public override string CreateType(IJsonStruct jsonStruct)
 {
     if (jsonStruct == null)
     {
         return(null);
     }
     else if (jsonStruct is IJsonString js)
     {
         return(js.String);
     }
     throw new Exception($"Cannot convert {jsonStruct.GetType().FullName} to a string.");
 }
Пример #9
0
 /// <summary>
 /// Inserts an item
 /// </summary>
 /// <param name="index"></param>
 /// <param name="item"></param>
 public void Insert(int index, IJsonStruct item)
 {
     SetParent(item);
     Elements.Insert(index, item);
 }
Пример #10
0
 /// <summary>
 /// Returns the index of supplied item
 /// </summary>
 /// <param name="item"></param>
 /// <returns></returns>
 public int IndexOf(IJsonStruct item)
 {
     return(Elements.IndexOf(item));
 }
Пример #11
0
 /// <summary>
 /// Removes suppied element.
 /// </summary>
 /// <param name="item"></param>
 /// <returns></returns>
 public bool Remove(IJsonStruct item)
 {
     RemoveParent(item);
     return(Elements.Remove(item));
 }
Пример #12
0
 /// <summary>
 /// Returns true if list contains the item.
 /// </summary>
 /// <param name="item"></param>
 /// <returns></returns>
 public bool Contains(IJsonStruct item)
 {
     return(Elements.Contains(item));
 }
Пример #13
0
 /// <summary>
 /// Adds an item
 /// </summary>
 /// <param name="item"></param>
 public void Add(IJsonStruct item)
 {
     SetParent(item);
     Elements.Add(item);
 }
Пример #14
0
 /// <summary>
 /// Creates the type
 /// </summary>
 /// <param name="jsonStruct"></param>
 /// <returns></returns>
 public abstract T CreateType(IJsonStruct jsonStruct);
Пример #15
0
 object IJsonTypeHandler.CreateType(IJsonStruct jsonStruct)
 {
     return(CreateType(jsonStruct));
 }
Пример #16
0
 public override TArr CreateType(IJsonStruct jsonStruct)
 {
     return((TArr)(object)new ArrayProxy <TElem>((IJsonArray)jsonStruct));
 }