/// <summary> /// Converts the given string <paramref name="value"/> to an ODataComplexValue or ODataCollectionValue and returns it. /// </summary> /// <remarks>Does not handle primitive values.</remarks> /// <param name="value">Value to be deserialized.</param> /// <param name="version">ODataVersion to be compliant with.</param> /// <param name="model">Model to use for verification.</param> /// <param name="typeReference">Expected type reference from deserialization. If null, verification will be skipped.</param> /// <returns>An ODataComplexValue or ODataCollectionValue that results from the deserialization of <paramref name="value"/>.</returns> internal static object ConvertFromComplexOrCollectionValue(string value, ODataVersion version, IEdmModel model, IEdmTypeReference typeReference) { DebugUtils.CheckNoExternalCallers(); ODataMessageReaderSettings settings = new ODataMessageReaderSettings(); using (StringReader reader = new StringReader(value)) { using (ODataJsonInputContext context = new ODataJsonInputContext( ODataFormat.VerboseJson, reader, settings, version, false /*readingResponse*/, true /*synchronous*/, model, null /*urlResolver*/)) { ODataJsonPropertyAndValueDeserializer deserializer = new ODataJsonPropertyAndValueDeserializer(context); deserializer.ReadPayloadStart(false); object rawResult = deserializer.ReadNonEntityValue(typeReference, null /*DuplicatePropertyNameChecker*/, null /*CollectionWithoutExpectedTypeValidator*/, true /*validateNullValue*/); deserializer.ReadPayloadEnd(false); Debug.Assert(rawResult is ODataComplexValue || rawResult is ODataCollectionValue, "rawResult is ODataComplexValue || rawResult is ODataCollectionValue"); return(rawResult); } } }
internal static object ConvertFromComplexOrCollectionValue(string value, ODataVersion version, IEdmModel model, IEdmTypeReference typeReference) { object obj3; ODataMessageReaderSettings messageReaderSettings = new ODataMessageReaderSettings(); using (StringReader reader = new StringReader(value)) { using (ODataJsonInputContext context = new ODataJsonInputContext(ODataFormat.VerboseJson, reader, messageReaderSettings, version, false, true, model, null)) { ODataJsonPropertyAndValueDeserializer deserializer = new ODataJsonPropertyAndValueDeserializer(context); deserializer.ReadPayloadStart(false); object obj2 = deserializer.ReadNonEntityValue(typeReference, null, null, true); deserializer.ReadPayloadEnd(false); obj3 = obj2; } } return obj3; }