void HandleUnexpectedItemInCollection(ref int iterator) { if (IsStartElement()) { context.SkipUnknownElement(xmlReader); iterator--; } else { throw XmlObjectSerializerReadContext.CreateUnexpectedStateException(XmlNodeType.Element, xmlReader); } }
private object ReadCollectionItems(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context, XmlDictionaryString collectionItemName, XmlDictionaryString collectionItemNamespace, CollectionDataContract collectionContract, object resultCollection, bool isReadOnlyCollection) { string itemName = GetCollectionContractItemName(collectionContract); string itemNs = GetCollectionContractNamespace(collectionContract); Type itemType = collectionContract.ItemType; CollectionReadItemDelegate collectionReadItemDelegate = GetCollectionReadItemDelegate(collectionContract); MethodInfo getCollectionSetItemDelegateMethod = s_getCollectionSetItemDelegateMethod.MakeGenericMethod(itemType); CollectionSetItemDelegate collectionSetItemDelegate = (CollectionSetItemDelegate)getCollectionSetItemDelegateMethod.Invoke(this, new object[] { collectionContract, resultCollection, isReadOnlyCollection }); int index = 0; while (true) { if (xmlReader.IsStartElement(collectionItemName, collectionItemNamespace)) { object collectionItem = collectionReadItemDelegate(xmlReader, context, collectionContract, itemType, itemName, itemNs); resultCollection = collectionSetItemDelegate(resultCollection, collectionItem, index); index++; } else { if (xmlReader.NodeType == XmlNodeType.EndElement) { break; } if (!xmlReader.IsStartElement()) { throw XmlObjectSerializerReadContext.CreateUnexpectedStateException(XmlNodeType.Element, xmlReader); } context.SkipUnknownElement(xmlReader); } } context.IncrementItemCount(index); if (!isReadOnlyCollection && IsArrayLikeCollection(collectionContract)) { MethodInfo trimArraySizeMethod = XmlFormatGeneratorStatics.TrimArraySizeMethod.MakeGenericMethod(itemType); resultCollection = trimArraySizeMethod.Invoke(null, new object[] { resultCollection, index }); } return(resultCollection); }