Beispiel #1
0
        ProxyArray DecodeArray()
        {
            var proxy = new ProxyArray();

            // Ditch opening bracket.
            json.Read();

            // [
            var parsing = true;

            while (parsing)
            {
                var nextToken = NextToken;

                // ReSharper disable once SwitchStatementMissingSomeCases
                switch (nextToken)
                {
                case Token.None:
                    return(null);

                case Token.Comma:
                    continue;

                case Token.CloseBracket:
                    parsing = false;
                    break;

                default:
                    proxy.Add(DecodeByToken(nextToken));
                    break;
                }
            }

            return(proxy);
        }
Beispiel #2
0
        // ReSharper disable once UnusedMember.Local
        static void DecodeMultiRankArray <T>(ProxyArray arrayData, Array array, int arrayRank, int[] indices)
        {
            var count = arrayData.Count;

            for (var i = 0; i < count; i++)
            {
                indices[arrayRank - 1] = i;
                if (arrayRank < array.Rank)
                {
                    DecodeMultiRankArray <T>(arrayData[i] as ProxyArray, array, arrayRank + 1, indices);
                }
                else
                {
                    array.SetValue(DecodeType <T>(arrayData[i]), indices);
                }
            }
        }
Beispiel #3
0
        void EncodeProxyArray(ProxyArray value)
        {
            if (value.Count == 0)
            {
                builder.Append("[]");
            }
            else
            {
                AppendOpenBracket();

                var firstItem = true;
                foreach (var obj in value)
                {
                    AppendComma(firstItem);
                    EncodeValue(obj, false);
                    firstItem = false;
                }

                AppendCloseBracket();
            }
        }