/// <summary> /// Creates an <see cref="ODataCollectionWriter" /> to write a collection of primitive or complex values (as result of a service operation invocation). /// </summary> /// <param name="itemTypeReference">The item type of the collection being written or null if no metadata is available.</param> /// <returns>The created collection writer.</returns> private ODataCollectionWriter CreateODataCollectionWriterImplementation(IEdmTypeReference itemTypeReference) { ODataJsonLightCollectionWriter jsonLightCollectionWriter = new ODataJsonLightCollectionWriter(this, itemTypeReference); this.outputInStreamErrorListener = jsonLightCollectionWriter; return(jsonLightCollectionWriter); }
/// <summary> /// Creates an <see cref="ODataCollectionWriter" /> to write a collection of primitive or complex values (as result of a service operation invocation). /// </summary> /// <param name="itemTypeReference">The item type of the collection being written or null if no metadata is available.</param> /// <returns>The created collection writer.</returns> private ODataCollectionWriter CreateODataCollectionWriterImplementation(IEdmTypeReference itemTypeReference) { ODataJsonLightCollectionWriter jsonLightCollectionWriter = new ODataJsonLightCollectionWriter(this, itemTypeReference); this.outputInStreamErrorListener = jsonLightCollectionWriter; return jsonLightCollectionWriter; }
private static void WriteAndValidateAsync(IEdmTypeReference itemTypeReference, ODataCollectionStart collectionStart, IEnumerable<object> items, string expectedPayload, bool writingResponse) { MemoryStream stream = new MemoryStream(); var outputContext = CreateJsonLightOutputContext(stream, writingResponse, synchronous: false); var collectionWriter = new ODataJsonLightCollectionWriter(outputContext, itemTypeReference); collectionWriter.WriteStartAsync(collectionStart).Wait(); foreach (object item in items) { collectionWriter.WriteItemAsync(item).Wait(); } collectionWriter.WriteEndAsync().Wait(); ValidateWrittenPayload(stream, expectedPayload); }