예제 #1
0
        internal JsonArray ReadArray(IEnumerable collection)
        {
            var array = new XNodeArray();

            foreach (var item in collection)
            {
                array.Add(ReadValue(item.GetType(), item));
            }

            return(array);
        }
예제 #2
0
        internal static XNodeArray Create <T>(T[] source, Func <T, JsonNode> selector)
        {
            if (source == null || selector == null)
            {
                return(null);
            }
            var result = new XNodeArray();

            foreach (var item in source.Select(selector))
            {
                result.SafeAdd(item);
            }
            return(result);
        }
예제 #3
0
        internal JsonArray ReadArray()
        {
            reader.Ensure(TokenKind.LeftBracket, "array");

            var array = new XNodeArray();

            reader.Next(); // Read the '[' (Array start)

            // Read the array's items
            while (reader.Current.Kind != TokenKind.RightBracket)
            {
                if (reader.Current.Kind == TokenKind.Comma)
                {
                    reader.Next(); // Read the ',' (Seperator)
                }

                if (reader.Current.IsLiteral)
                {
                    array.Add(ReadLiteral()); // Boolean, Date, Number, Null, String, Uri
                }
                else if (reader.Current.Kind == TokenKind.LeftBracket)
                {
                    array.Add(ReadArray()); // Array
                }
                else if (reader.Current.Kind == TokenKind.LeftBrace)
                {
                    array.Add(ReadObject()); // Object
                }
                else
                {
                    throw new ParserException($"Expected comma, literal, or object. Was {reader.Current}.");
                }
            }

            reader.Next(); // Read the ']' (Array end)

            return(array);
        }