public Dictionary <TKey, TValue> Unmarshall(XmlUnmarshallerContext context)
        {
            var originalDepth = context.CurrentDepth;
            var targetDepth   = originalDepth + 1;

            // If a dictionary is present in the response, use AlwaysSendDictionary,
            // so if the response was empty, reusing the object in the request we will
            // end up sending the same empty collection back.
            var dictionary = new AlwaysSendDictionary <TKey, TValue>();

            while (context.Read())
            {
                if (context.IsEndElement && context.CurrentDepth < originalDepth)
                {
                    break;
                }

                var item = KVUnmarshaller.Unmarshall(context);
                dictionary.Add(item.Key, item.Value);
            }

            return(dictionary);
        }
Esempio n. 2
0
        public Dictionary <TKey, TValue> Unmarshall(JsonUnmarshallerContext context)
        {
            context.Read();
            if (context.CurrentTokenType == JsonToken.Null)
            {
                return(new Dictionary <TKey, TValue>());
            }
            Dictionary <TKey, TValue> dictionary = new AlwaysSendDictionary <TKey, TValue>();

            while (!context.Peek(JsonToken.ObjectEnd))
            {
                KeyValuePair <TKey, TValue> keyValuePair = KVUnmarshaller.Unmarshall(context);
                dictionary.Add(keyValuePair.Key, keyValuePair.Value);
            }
            context.Read();
            return(dictionary);
        }
Esempio n. 3
0
        public Dictionary <K, V> Unmarshall(JsonUnmarshallerContext context)
        {
            context.Read(); // Read { or null
            Dictionary <K, V> dictionary = new Dictionary <K, V>();

            if (context.CurrentTokenType == JsonToken.Null)
            {
                return(dictionary);
            }

            while (!context.Peek(JsonToken.ObjectEnd)) // Peek }
            {
                KeyValuePair <K, V> item = KVUnmarshaller.Unmarshall(context);
                dictionary.Add(item.Key, item.Value);
            }
            context.Read(); // Read }
            return(dictionary);
        }
        public Dictionary <TKey, TValue> Unmarshall(JsonUnmarshallerContext context)
        {
            context.Read(); // Read { or null
            if (context.CurrentTokenType == JsonToken.Null)
            {
                return(new Dictionary <TKey, TValue>());
            }

            // If a dictionary is present in the response, use AlwaysSendDictionary,
            // so if the response was empty, reusing the object in the request we will
            // end up sending the same empty collection back.
            Dictionary <TKey, TValue> dictionary = new AlwaysSendDictionary <TKey, TValue>();

            while (!context.Peek(JsonToken.ObjectEnd)) // Peek }
            {
                KeyValuePair <TKey, TValue> item = KVUnmarshaller.Unmarshall(context);
                dictionary.Add(item.Key, item.Value);
            }
            context.Read(); // Read }
            return(dictionary);
        }
        public Dictionary <K, V> Unmarshall(JsonUnmarshallerContext context)
        {
            Dictionary <K, V> dictionary = new Dictionary <K, V>();

            int originalDepth = context.CurrentDepth;
            int targetDepth   = originalDepth;

            while (context.Read())
            {
                if ((context.IsKey) && (context.CurrentDepth == targetDepth + 1))
                {
                    KeyValuePair <K, V> item = KVUnmarshaller.Unmarshall(context);
                    dictionary.Add(item.Key, item.Value);
                }
                else if (context.IsEndElement || (context.CurrentDepth < originalDepth))
                {
                    break;
                }
            }

            return(dictionary);
        }