Example #1
0
        ProxyArray DecodeArray()
        {
            ProxyArray array = new ProxyArray();

            // ditch opening bracket
            json.Read();

            // [
            var parsing = true;

            while (parsing)
            {
                TOKEN nextToken = NextToken;

                switch (nextToken)
                {
                case TOKEN.NONE:
                    return(null);

                case TOKEN.COMMA:
                    continue;

                case TOKEN.SQUARED_CLOSE:
                    parsing = false;
                    break;

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

            return(array);
        }
        ProxyArray DecodeArray()
        {
            ProxyArray proxy = new ProxyArray();

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

            // [
            var parsing = true;

            while (parsing)
            {
                Token nextToken = NextToken;

                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);
        }
Example #3
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);
        }
Example #4
0
        private static void DecodeMultiRankArray <T>(ProxyArray arrayData, Array array, int arrayRank, int[] indices)
        {
            var count = arrayData.Count;

            for (int 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);
                }
            }
        }
Example #5
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();
            }
        }
Example #6
0
        private static Variant FindIndex(ProxyArray array, int index)
        {
            for (int i = 0; i < array.Count; i++)
            {
                if (array[i] is ProxyObject)
                {
                    ProxyObject proxy = array[i] as ProxyObject;

                    if (proxy.ContainsKey(ProxyArray.CombineHintName))
                    {
                        int @Index = proxy[ProxyArray.CombineHintName];

                        if (@Index == index)
                        {
                            return(proxy);
                        }
                    }
                }
            }
            return(null);
        }
Example #7
0
        protected static Variant CombineVariant(Variant startingVariant, Variant combineWith)
        {
            Type type = null;

            if (startingVariant != null)
            {
                type = startingVariant.GetType();
            }
            else if (combineWith != null)
            {
                type = combineWith.GetType();
            }
            else
            {
                throw new ArgumentException("Both values are null for combine");
            }

            if (type == typeof(ProxyObject))
            {
                ProxyObject combineObject  = combineWith as ProxyObject;
                ProxyObject startingObject = startingVariant as ProxyObject;

                foreach (var item in combineObject)
                {
                    if (startingObject.ContainsKey(item.Key))
                    {
                        //It had the value so we have to loop over it.
                        startingObject[item.Key] = CombineVariant(startingObject[item.Key], item.Value);
                    }
                    else
                    {
                        //It did not have a value so we can just copy the whole tree
                        startingObject[item.Key] = item.Value;
                    }
                }
            }
            else if (type == typeof(ProxyArray))
            {
                ProxyArray combineArray  = combineWith as ProxyArray;
                ProxyArray startingArray = startingVariant as ProxyArray;

                for (int i = 0; i < combineArray.Count; i++)
                {
                    if (combineArray[i] is ProxyObject)
                    {
                        ProxyObject arrayObject = combineArray[i] as ProxyObject;

                        if (arrayObject != null)
                        {
                            if (arrayObject.ContainsKey(ProxyArray.CombineHintName))
                            {
                                int @Index = arrayObject[ProxyArray.CombineHintName];

                                Variant indexVariant = FindIndex(startingArray, @Index);

                                if (indexVariant == null)
                                {
                                    startingArray.Add(arrayObject);
                                }
                                else
                                {
                                    indexVariant = CombineVariant(indexVariant, arrayObject);
                                }
                            }
                        }
                    }
                }
            }
            else if (type == typeof(ProxyNumber))
            {
                startingVariant = combineWith;
            }
            else if (type == typeof(ProxyString))
            {
                startingVariant = combineWith;
            }

            return(startingVariant);
        }