private ODataEntityReferenceLinks ReadLinksElement() { ODataEntityReferenceLinks links = new ODataEntityReferenceLinks(); List <ODataEntityReferenceLink> sourceList = new List <ODataEntityReferenceLink>(); DuplicateEntityReferenceLinksElementBitMask none = DuplicateEntityReferenceLinksElementBitMask.None; if (base.XmlReader.IsEmptyElement) { goto Label_018C; } base.XmlReader.Read(); Label_002A: switch (base.XmlReader.NodeType) { case XmlNodeType.Element: if ((base.XmlReader.NamespaceEquals(base.XmlReader.ODataMetadataNamespace) && base.XmlReader.LocalNameEquals(this.ODataCountElementName)) && (base.Version >= ODataVersion.V2)) { VerifyEntityReferenceLinksElementNotFound(ref none, DuplicateEntityReferenceLinksElementBitMask.Count, base.XmlReader.ODataMetadataNamespace, "count"); long num = (long)AtomValueUtils.ReadPrimitiveValue(base.XmlReader, EdmCoreModel.Instance.GetInt64(false)); links.Count = new long?(num); base.XmlReader.Read(); goto Label_017A; } if (base.XmlReader.NamespaceEquals(base.XmlReader.ODataNamespace)) { if (base.XmlReader.LocalNameEquals(this.ODataUriElementName)) { ODataEntityReferenceLink item = this.ReadUriElement(); sourceList.Add(item); goto Label_017A; } if (base.XmlReader.LocalNameEquals(this.ODataNextElementName) && (base.Version >= ODataVersion.V2)) { VerifyEntityReferenceLinksElementNotFound(ref none, DuplicateEntityReferenceLinksElementBitMask.NextLink, base.XmlReader.ODataNamespace, "next"); Uri xmlBaseUri = base.XmlReader.XmlBaseUri; string uriFromPayload = base.XmlReader.ReadElementValue(); links.NextPageLink = base.ProcessUriFromPayload(uriFromPayload, xmlBaseUri); goto Label_017A; } } break; case XmlNodeType.EndElement: goto Label_017A; } base.XmlReader.Skip(); Label_017A: if (base.XmlReader.NodeType != XmlNodeType.EndElement) { goto Label_002A; } Label_018C: base.XmlReader.Read(); links.Links = new ReadOnlyEnumerable <ODataEntityReferenceLink>(sourceList); return(links); }
/// <summary> /// Read a primitive value from the reader. /// </summary> /// <param name="actualValueTypeReference">The type of the value to read.</param> /// <returns>The value read from the payload and converted as appropriate to the target type.</returns> /// <remarks> /// Pre-Condition: XmlNodeType.Element - the element to read the value for. /// XmlNodeType.Attribute - an attribute on the element to read the value for. /// Post-Condition: XmlNodeType.Element - the element was empty. /// XmlNodeType.EndElement - the element had some value. /// /// Note that this method will not read null values, those should be handled by the caller already. /// </remarks> private object ReadPrimitiveValue(IEdmPrimitiveTypeReference actualValueTypeReference) { Debug.Assert(actualValueTypeReference != null, "actualValueTypeReference != null"); Debug.Assert(actualValueTypeReference.TypeKind() == EdmTypeKind.Primitive, "Only primitive values can be read by this method."); this.AssertXmlCondition(XmlNodeType.Element, XmlNodeType.Attribute); object result = AtomValueUtils.ReadPrimitiveValue(this.XmlReader, actualValueTypeReference); this.AssertXmlCondition(true, XmlNodeType.EndElement); Debug.Assert(result != null, "The method should never return null since it doesn't handle null values."); return(result); }
/// <summary> /// Reads all top-level entity reference links and the (optional) inline count and next link elements. /// </summary> /// <returns>An <see cref="ODataEntityReferenceLinks"/> instance representing the read entity reference links.</returns> /// <remarks> /// Pre-Condition: XmlNodeType.Element - The 'd:links' element. /// Post-Condtion: any - The node after the 'd:links' end element (or empty 'd:links' element). /// </remarks> private ODataEntityReferenceLinks ReadLinksElement() { Debug.Assert(this.XmlReader != null, "this.XmlReader != null"); this.AssertXmlCondition(XmlNodeType.Element); Debug.Assert(this.XmlReader.NamespaceURI == this.XmlReader.ODataNamespace, "this.XmlReader.NamespaceURI == this.XmlReader.ODataNamespace"); Debug.Assert(this.XmlReader.LocalName == AtomConstants.ODataLinksElementName, "this.XmlReader.LocalName == AtomConstants.ODataLinksElementName"); ODataEntityReferenceLinks links = new ODataEntityReferenceLinks(); List <ODataEntityReferenceLink> linkList = new List <ODataEntityReferenceLink>(); DuplicateEntityReferenceLinksElementBitMask elementsReadBitmask = DuplicateEntityReferenceLinksElementBitMask.None; if (!this.XmlReader.IsEmptyElement) { // Move to the first child node of the element. this.XmlReader.Read(); do { switch (this.XmlReader.NodeType) { case XmlNodeType.EndElement: // end of the <links> element continue; case XmlNodeType.Element: // <m:count> if (this.XmlReader.NamespaceEquals(this.XmlReader.ODataMetadataNamespace) && this.XmlReader.LocalNameEquals(this.ODataCountElementName) && this.Version >= ODataVersion.V2) { VerifyEntityReferenceLinksElementNotFound( ref elementsReadBitmask, DuplicateEntityReferenceLinksElementBitMask.Count, this.XmlReader.ODataMetadataNamespace, AtomConstants.ODataCountElementName); // Note that we allow negative values to be read. long countValue = (long)AtomValueUtils.ReadPrimitiveValue(this.XmlReader, EdmCoreModel.Instance.GetInt64(false)); links.Count = countValue; // Read over the end element of the <m:count> element this.XmlReader.Read(); continue; } if (this.XmlReader.NamespaceEquals(this.XmlReader.ODataNamespace)) { // <d:uri> if (this.XmlReader.LocalNameEquals(this.ODataUriElementName)) { ODataEntityReferenceLink link = this.ReadUriElement(); linkList.Add(link); continue; } // <d:next> if (this.XmlReader.LocalNameEquals(this.ODataNextElementName) && this.Version >= ODataVersion.V2) { VerifyEntityReferenceLinksElementNotFound( ref elementsReadBitmask, DuplicateEntityReferenceLinksElementBitMask.NextLink, this.XmlReader.ODataNamespace, AtomConstants.ODataNextLinkElementName); // NOTE: get the base URI here before we read the content as string; reading the content as string will move the // reader to the end element and thus we lose the xml:base definition on the element. Uri xmlBaseUri = this.XmlReader.XmlBaseUri; string uriString = this.XmlReader.ReadElementValue(); links.NextPageLink = this.ProcessUriFromPayload(uriString, xmlBaseUri); continue; } } break; default: break; } this.XmlReader.Skip(); }while (this.XmlReader.NodeType != XmlNodeType.EndElement); } // Read over the end element, or empty start element. this.XmlReader.Read(); links.Links = new ReadOnlyEnumerable <ODataEntityReferenceLink>(linkList); return(links); }
private object ReadPrimitiveValue(IEdmPrimitiveTypeReference actualValueTypeReference) { return(AtomValueUtils.ReadPrimitiveValue(base.XmlReader, actualValueTypeReference)); }