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);
        }
Exemple #2
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);
        }
Exemple #3
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);
        }
Exemple #4
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);
        }