Ejemplo n.º 1
0
 public LinkedItem(IDataWriter source, RWPathInfo sourcePath, IDataWriter destination, RWPathInfo destinationPath)
 {
     Source          = source;
     SourcePath      = sourcePath;
     Destination     = destination;
     DestinationPath = destinationPath;
 }
Ejemplo n.º 2
0
        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();
        }
Ejemplo n.º 3
0
            public object GetValue(RWPathInfo reference)
            {
                AddItem(new LinkedItem(
                            root.DataWriter,
                            reference,
                            curr.DataWriter,
                            curr.CurrentKey.Clone()
                            ));

                return(null);
            }
Ejemplo n.º 4
0
 public void SetCurrentKey <TKey>(TKey key)
 {
     if (curr.CurrentKey is null)
     {
         curr.CurrentKey = RWPathInfo.Create(key);
     }
     else
     {
         RWPathInfo.SetPath(curr.CurrentKey, key);
     }
 }
Ejemplo n.º 5
0
        public IValueWriter this[int key]
        {
            get
            {
                if (typeof(TMode) == typeof(JsonSerializeModes.ReferenceMode))
                {
                    Reference = RWPathInfo.Create(key, Reference.Parent);
                }

                return(this);
            }
        }
Ejemplo n.º 6
0
        public bool IsLoopReferencing(RWPathInfo reference)
        {
            var curr = Reference;

            while ((curr = curr.Parent) != null)
            {
                if (curr.Equals(reference))
                {
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 7
0
            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);
            }
Ejemplo n.º 8
0
        public IValueWriter this[string key]
        {
            get
            {
                if (typeof(TMode) == typeof(JsonSerializeModes.ReferenceMode))
                {
                    Reference = RWPathInfo.Create(key, Reference.Parent);
                }

                AppendKeyBefore();

                InternalWriteString(key);

                AppendKeyAfter();

                return(this);
            }
        }
Ejemplo n.º 9
0
            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));
                }
            }
Ejemplo n.º 10
0
 public Item(JsonReference source, IDataWriter writer, RWPathInfo destination)
 {
     Source      = source;
     Writer      = writer;
     Destination = destination;
 }
Ejemplo n.º 11
0
 /// <summary>
 /// 构建实例
 /// </summary>
 internal JsonLoopReferencingException(RWPathInfo ref1, RWPathInfo ref2, object loopingObject)
     : base($"Json serializating members '{ref1}' and '{ref2}' loop referencing.")
 {
     LoopingObject = loopingObject;
 }
Ejemplo n.º 12
0
        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();
        }
Ejemplo n.º 13
0
        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))
 {
 }
Ejemplo n.º 15
0
 public JsonReference(IDataReader root, RWPathInfo reference)
 {
     Root      = root;
     Reference = reference;
 }