public LinkedItem(IDataWriter source, RWPathInfo sourcePath, IDataWriter destination, RWPathInfo destinationPath) { Source = source; SourcePath = sourcePath; Destination = destination; DestinationPath = destinationPath; }
public void WriteReference(RWPathInfo reference) { WriteValueBefore(); Expand(2); Append(FixObject); AppendMiddleChars(); Expand(8); // "$ref" Append(RefKeyString); AppendKeyAfter(); Expand(2); Append(FixString); WriteReferenceItem(reference); Expand(3); Append(FixString); AppendMiddleChars(); Append(ObjectEnding); AppendValueAfter(); }
public object GetValue(RWPathInfo reference) { AddItem(new LinkedItem( root.DataWriter, reference, curr.DataWriter, curr.CurrentKey.Clone() )); return(null); }
public void SetCurrentKey <TKey>(TKey key) { if (curr.CurrentKey is null) { curr.CurrentKey = RWPathInfo.Create(key); } else { RWPathInfo.SetPath(curr.CurrentKey, key); } }
public IValueWriter this[int key] { get { if (typeof(TMode) == typeof(JsonSerializeModes.ReferenceMode)) { Reference = RWPathInfo.Create(key, Reference.Parent); } return(this); } }
public bool IsLoopReferencing(RWPathInfo reference) { var curr = Reference; while ((curr = curr.Parent) != null) { if (curr.Equals(reference)) { return(true); } } return(false); }
public JsonReference CreateJsonReference(RWPathInfo reference) { if (root == null) { throw new NotSupportedException("Json root is not initialized."); } var result = new JsonReference(root, reference); // if (!result.TryGetValue(out var value) || value is ValueType) { jsonReference = result; } return(result); }
public IValueWriter this[string key] { get { if (typeof(TMode) == typeof(JsonSerializeModes.ReferenceMode)) { Reference = RWPathInfo.Create(key, Reference.Parent); } AppendKeyBefore(); InternalWriteString(key); AppendKeyAfter(); return(this); } }
public void SetItem(IDataWriter writer, RWPathInfo destination) { if (items == null) { items = new LinkedList <Item>(); } if (jsonReference != null) { items.AddLast(new Item(jsonReference, writer, destination)); jsonReference = null; } else if (items != null && items.Count != 0 && items.Last.Value.Writer is IDataReader reader) { var jsonReference = new JsonReference(reader, RWPathInfo.Root); items.AddLast(new Item(jsonReference, writer, destination)); } }
public Item(JsonReference source, IDataWriter writer, RWPathInfo destination) { Source = source; Writer = writer; Destination = destination; }
/// <summary> /// 构建实例 /// </summary> internal JsonLoopReferencingException(RWPathInfo ref1, RWPathInfo ref2, object loopingObject) : base($"Json serializating members '{ref1}' and '{ref2}' loop referencing.") { LoopingObject = loopingObject; }
public void WriteObject(IDataReader <string> dataReader) { if (typeof(TMode) == typeof(JsonSerializeModes.ReferenceMode)) { if ((Options & (JsonFormatterOptions.MultiReferencingNull | JsonFormatterOptions.LoopReferencingNull)) != 0 && (Options & JsonFormatterOptions.IgnoreNull) != 0 && !Reference.IsRoot) { } else if (!CheckObjectReference(dataReader)) { return; } } WriteValueBefore(); Expand(2); Append(FixObject); AppendStructBefore(); var isInArray = false; if (typeof(TMode) != typeof(JsonSerializeModes.SimpleMode)) { isInArray = IsInArray; IsInArray = false; } int tOffset = offset; if (AddDepth()) { if (typeof(TMode) == typeof(JsonSerializeModes.SimpleMode)) { dataReader.OnReadAll(this); } else { if (typeof(TMode) == typeof(JsonSerializeModes.ReferenceMode)) { if (dataReader.Count != 0) { dataReader.OnReadAll(References); } Reference = RWPathInfo.Create(string.Empty, Reference); } if (Options >= JsonFormatterOptions.IgnoreNull) { dataReader.OnReadAll(this, this); } else { dataReader.OnReadAll(this); } if (typeof(TMode) == typeof(JsonSerializeModes.ReferenceMode)) { Reference = Reference.Parent; } } } SubtractDepth(); Expand(2); if (tOffset != offset) { --offset; } AppendStructAfter(); Append(ObjectEnding); if (typeof(TMode) != typeof(JsonSerializeModes.SimpleMode)) { IsInArray = isInArray; } AppendValueAfter(); }
public void WriteReferenceItem(RWPathInfo reference) { if (reference.Parent != null) { WriteReferenceItem(reference.Parent); } if (reference.IsRoot) { Expand(2); // Root Append(ReferenceRootPathName); return; } Expand(2); Append(ReferenceSeparator); var key = reference.GetKey(); if (key is int intKey) { InternalWriteInt64(intKey); } else { var name = key.ToString(); Expand(name.Length * 3); for (int i = 0; i < name.Length; i++) { var c = name[i]; switch (c) { case '\\': // %5C Append('%'); Append('5'); Append('C'); break; case '/': // %2F Append('%'); Append('2'); Append('F'); break; case '"': // %22 Append('%'); Append('2'); Append('2'); break; default: Append(c); break; } } } }
/// <summary> /// 初始化实例 /// </summary> internal JsonLoopReferencingException(RWPathInfo ref1, RWPathInfo ref2) : base(string.Format("Json serializating members '{0}' and '{1}' loop referencing.", ref1, ref2)) { }
public JsonReference(IDataReader root, RWPathInfo reference) { Root = root; Reference = reference; }