internal ODataEntityReferenceLinks ReadEntityReferenceLinks() { bool flag = (base.Version >= ODataVersion.V2) && base.ReadingResponse; ODataJsonReaderUtils.EntityReferenceLinksWrapperPropertyBitMask none = ODataJsonReaderUtils.EntityReferenceLinksWrapperPropertyBitMask.None; ODataEntityReferenceLinks entityReferenceLinks = new ODataEntityReferenceLinks(); base.ReadPayloadStart(false); if (flag) { base.JsonReader.ReadStartObject(); if (!this.ReadEntityReferenceLinkProperties(entityReferenceLinks, ref none)) { throw new ODataException(Strings.ODataJsonEntityReferenceLinkDeserializer_ExpectedEntityReferenceLinksResultsPropertyNotFound); } } base.JsonReader.ReadStartArray(); List <ODataEntityReferenceLink> sourceList = new List <ODataEntityReferenceLink>(); while (base.JsonReader.NodeType != JsonNodeType.EndArray) { ODataEntityReferenceLink item = this.ReadSingleEntityReferenceLink(); sourceList.Add(item); } base.JsonReader.ReadEndArray(); if (flag) { this.ReadEntityReferenceLinkProperties(entityReferenceLinks, ref none); base.JsonReader.ReadEndObject(); } entityReferenceLinks.Links = new ReadOnlyEnumerable <ODataEntityReferenceLink>(sourceList); base.ReadPayloadEnd(false); return(entityReferenceLinks); }
/// <summary> /// Reads the properties of an entity reference link. /// </summary> /// <param name="entityReferenceLinks">The <see cref="ODataEntityReferenceLinks"/> instance to set the read property values on.</param> /// <param name="propertiesFoundBitField">The bit field with all the properties already read.</param> /// <returns>true if the method found the 'results' property; otherwise false.</returns> private bool ReadEntityReferenceLinkProperties( ODataEntityReferenceLinks entityReferenceLinks, ref ODataJsonReaderUtils.EntityReferenceLinksWrapperPropertyBitMask propertiesFoundBitField) { Debug.Assert(entityReferenceLinks != null, "entityReferenceLinks != null"); this.JsonReader.AssertNotBuffering(); while (this.JsonReader.NodeType == JsonNodeType.Property) { string propertyName = this.JsonReader.ReadPropertyName(); switch (propertyName) { case JsonConstants.ODataResultsName: ODataJsonReaderUtils.VerifyEntityReferenceLinksWrapperPropertyNotFound( ref propertiesFoundBitField, ODataJsonReaderUtils.EntityReferenceLinksWrapperPropertyBitMask.Results, JsonConstants.ODataResultsName); this.JsonReader.AssertNotBuffering(); return(true); case JsonConstants.ODataCountName: ODataJsonReaderUtils.VerifyEntityReferenceLinksWrapperPropertyNotFound( ref propertiesFoundBitField, ODataJsonReaderUtils.EntityReferenceLinksWrapperPropertyBitMask.Count, JsonConstants.ODataCountName); object countValue = this.JsonReader.ReadPrimitiveValue(); long? count = (long?)ODataJsonReaderUtils.ConvertValue(countValue, EdmCoreModel.Instance.GetInt64(true), this.MessageReaderSettings, this.Version, /*validateNullValue*/ true); ODataJsonReaderUtils.ValidateCountPropertyInEntityReferenceLinks(count); entityReferenceLinks.Count = count; break; case JsonConstants.ODataNextLinkName: ODataJsonReaderUtils.VerifyEntityReferenceLinksWrapperPropertyNotFound( ref propertiesFoundBitField, ODataJsonReaderUtils.EntityReferenceLinksWrapperPropertyBitMask.NextPageLink, JsonConstants.ODataNextLinkName); string nextLinkString = this.JsonReader.ReadStringValue(JsonConstants.ODataNextLinkName); ODataJsonReaderUtils.ValidateEntityReferenceLinksStringProperty(nextLinkString, JsonConstants.ODataNextLinkName); entityReferenceLinks.NextPageLink = this.ProcessUriFromPayload(nextLinkString); break; default: // Skip all unrecognized properties this.JsonReader.SkipValue(); break; } } this.JsonReader.AssertNotBuffering(); return(false); }
/// <summary> /// Read a set of top-level entity reference links. /// </summary> /// <returns>An <see cref="ODataEntityReferenceLinks"/> representing the read links.</returns> internal ODataEntityReferenceLinks ReadEntityReferenceLinks() { DebugUtils.CheckNoExternalCallers(); Debug.Assert(this.JsonReader.NodeType == JsonNodeType.None, "Pre-Condition: expected JsonNodeType.None, the reader must not have been used yet."); this.JsonReader.AssertNotBuffering(); // Set to true if the entity reference links are expected to have the 'results' wrapper. // Entity reference links are only expected to have a results wrapper if // (a) the protocol version is >= 2 AND // (b) we are reading a response // NOTE: OIPI does not specify a format for >= v2 entity reference links in requests; we thus use the v1 format and consequently do not expect a result wrapper. bool isResultsWrapperExpected = this.Version >= ODataVersion.V2 && this.ReadingResponse; ODataJsonReaderUtils.EntityReferenceLinksWrapperPropertyBitMask propertiesFoundBitField = ODataJsonReaderUtils.EntityReferenceLinksWrapperPropertyBitMask.None; ODataEntityReferenceLinks entityReferenceLinks = new ODataEntityReferenceLinks(); // Read the response wrapper "d" if expected. this.ReadPayloadStart(false /*isReadingNestedPayload*/); if (isResultsWrapperExpected) { // Read the start object of the results wrapper object this.JsonReader.ReadStartObject(); bool foundResultsProperty = this.ReadEntityReferenceLinkProperties(entityReferenceLinks, ref propertiesFoundBitField); if (!foundResultsProperty) { throw new ODataException(Strings.ODataJsonEntityReferenceLinkDeserializer_ExpectedEntityReferenceLinksResultsPropertyNotFound); } } // Read the start of the content array of the links this.JsonReader.ReadStartArray(); List <ODataEntityReferenceLink> links = new List <ODataEntityReferenceLink>(); while (this.JsonReader.NodeType != JsonNodeType.EndArray) { // read another link ODataEntityReferenceLink entityReferenceLink = this.ReadSingleEntityReferenceLink(); links.Add(entityReferenceLink); } // Read over the end object - note that this might be the last node in the input (in case there's no response wrapper) this.JsonReader.ReadEndArray(); if (isResultsWrapperExpected) { this.ReadEntityReferenceLinkProperties(entityReferenceLinks, ref propertiesFoundBitField); // Read the end object of the results wrapper object this.JsonReader.ReadEndObject(); } entityReferenceLinks.Links = new ReadOnlyEnumerable <ODataEntityReferenceLink>(links); // Read the end of the response wrapper "d" if expected. this.ReadPayloadEnd(false /*isReadingNestedPayload*/); Debug.Assert(this.JsonReader.NodeType == JsonNodeType.EndOfInput, "Post-Condition: expected JsonNodeType.EndOfInput"); this.JsonReader.AssertNotBuffering(); return(entityReferenceLinks); }
private bool ReadEntityReferenceLinkProperties(ODataEntityReferenceLinks entityReferenceLinks, ref ODataJsonReaderUtils.EntityReferenceLinksWrapperPropertyBitMask propertiesFoundBitField) { while (base.JsonReader.NodeType == JsonNodeType.Property) { string str3 = base.JsonReader.ReadPropertyName(); if (str3 == null) { goto Label_00D9; } if (!(str3 == "results")) { if (str3 == "__count") { goto Label_0057; } if (str3 == "__next") { goto Label_00A2; } goto Label_00D9; } ODataJsonReaderUtils.VerifyEntityReferenceLinksWrapperPropertyNotFound(ref propertiesFoundBitField, ODataJsonReaderUtils.EntityReferenceLinksWrapperPropertyBitMask.Results, "results"); return(true); Label_0057: ODataJsonReaderUtils.VerifyEntityReferenceLinksWrapperPropertyNotFound(ref propertiesFoundBitField, ODataJsonReaderUtils.EntityReferenceLinksWrapperPropertyBitMask.Count, "__count"); long?propertyValue = (long?)ODataJsonReaderUtils.ConvertValue(base.JsonReader.ReadPrimitiveValue(), EdmCoreModel.Instance.GetInt64(true), base.MessageReaderSettings, base.Version, true); ODataJsonReaderUtils.ValidateCountPropertyInEntityReferenceLinks(propertyValue); entityReferenceLinks.Count = propertyValue; continue; Label_00A2: ODataJsonReaderUtils.VerifyEntityReferenceLinksWrapperPropertyNotFound(ref propertiesFoundBitField, ODataJsonReaderUtils.EntityReferenceLinksWrapperPropertyBitMask.NextPageLink, "__next"); string str2 = base.JsonReader.ReadStringValue("__next"); ODataJsonReaderUtils.ValidateEntityReferenceLinksStringProperty(str2, "__next"); entityReferenceLinks.NextPageLink = base.ProcessUriFromPayload(str2); continue; Label_00D9: base.JsonReader.SkipValue(); } return(false); }