Exemple #1
0
        internal static void WriteMultidimensionalArray(Array value, JsonSerializerHandler handler)
        {
            if (handler.Option.ReferenceLoopHandling != JsonReferenceHandlingEnum.None)
            {
                if (handler.SerializeStacks.Contains(value))
                {
                    if (handler.Option.ReferenceLoopHandling == JsonReferenceHandlingEnum.Null)
                    {
                        handler.Writer.Append("null");
                    }
                    else if (handler.Option.ReferenceLoopHandling == JsonReferenceHandlingEnum.Empty)
                    {
                        handler.Writer.Append("[]");
                    }
                    else if (handler.Option.ReferenceLoopHandling == JsonReferenceHandlingEnum.Remove)
                    {
                        RemoveWriterHelper.RemoveArrayItem(handler.Writer);
                    }
                    return;
                }
                handler.SerializeStacks.Push(value);
            }
            var action = SerializerObjectJump.GetThreadSafetyJumpAction(value.GetType().GetElementType());

            handler.Writer.Append("[");
            var enumerator = value.GetEnumerator();

            MultidimensionalWrite(enumerator, handler, value, action, value.GetLength(0), 0);
            handler.Writer.Append("]");
            if (handler.Option.ReferenceLoopHandling != JsonReferenceHandlingEnum.None)
            {
                handler.SerializeStacks.Pop();
            }
        }
Exemple #2
0
        internal static void WriteIEnumerable(IEnumerable value, JsonSerializerHandler handler)
        {
            if (handler.Option.ReferenceLoopHandling != JsonReferenceHandlingEnum.None)
            {
                if (handler.SerializeStacks.Contains(value))
                {
                    if (handler.Option.ReferenceLoopHandling == JsonReferenceHandlingEnum.Null)
                    {
                        handler.Writer.Append("null");
                    }
                    else if (handler.Option.ReferenceLoopHandling == JsonReferenceHandlingEnum.Empty)
                    {
                        handler.Writer.Append("[]");
                    }
                    else if (handler.Option.ReferenceLoopHandling == JsonReferenceHandlingEnum.Remove)
                    {
                        RemoveWriterHelper.RemoveArrayItem(handler.Writer);
                    }
                    return;
                }
                handler.SerializeStacks.Push(value);
            }

            handler.Writer.Append("[");
            bool isFirst = true;

            foreach (var obj in value)
            {
                if (isFirst)
                {
                    isFirst = false;
                }
                else
                {
                    handler.Writer.Append(",");
                }
                PrimitiveNormal.WriteValue(obj, handler);
            }
            handler.Writer.Append("]");
            if (handler.Option.ReferenceLoopHandling != JsonReferenceHandlingEnum.None)
            {
                handler.SerializeStacks.Pop();
            }
        }