Ejemplo n.º 1
0
        private void ReadItem(IDeserializerContext context, IDictionary <TKey, TValue> dictionary)
        {
            if (context.NodeType != XmlNodeType.Element || context.LocalName != "item")
            {
                throw new InvalidOperationException("Dictionary is not at an item element");
            }

            context.Read();

            object key = context.Deserialize(context.Namespace);

            object element = context.Deserialize(context.Namespace);

            if (context.NodeType != XmlNodeType.EndElement || context.LocalName != "item")
            {
                throw new InvalidOperationException("Dictionary is not at the end of an item");
            }

            context.Read();

            if (key != null)
            {
                dictionary.Add((TKey)key, (TValue)element);
            }
        }
Ejemplo n.º 2
0
        private void ReadProperty(IDeserializerContext context, T instance)
        {
            DeserializeObjectProperty <T> property;

            if (_propertyCache.TryGetProperty(context.LocalName, out property))
            {
                object value = context.Deserialize(context.Namespace);

                property.SetValue(instance, value);
            }
            else
            {
                if (_log.IsDebugEnabled)
                {
                    _log.Debug("No property " + context.LocalName + " in class " + typeof(T).ToFriendlyName() + " for deserialization");
                }

                context.Deserialize(context.Namespace);
            }
        }
Ejemplo n.º 3
0
        public virtual List <T> DeserializeAsList(IDeserializerContext context)
        {
            List <T> list = new List <T>();

            if (ListIsEmpty(context))
            {
                return(list);
            }

            MoveToFirstElement(context);

            while (context.NodeType != XmlNodeType.EndElement)
            {
                object element = context.Deserialize(context.Namespace);
                if (element != null)
                {
                    list.Add((T)element);
                }
            }

            MovePastEndElement(context);

            return(list);
        }