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); } }
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); } }
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); }