Example #1
0
        /// <summary>
        /// Start writing a collection - implementation of the actual functionality.
        /// </summary>
        /// <param name="collectionStart">The <see cref="ODataCollectionStart"/> representing the collection.</param>
        private void WriteStartImplementation(ODataCollectionStart collectionStart)
        {
            this.StartPayloadInStartState();
            this.EnterScope(CollectionWriterState.Collection, collectionStart);
            this.InterceptException(() =>
            {
                if (this.expectedItemType == null)
                {
                    this.collectionValidator = new CollectionWithoutExpectedTypeValidator(/*expectedItemTypeName*/ null);
                }

                this.StartCollection(collectionStart);
            });
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="inputContext">The input to read from.</param>
        /// <param name="expectedItemTypeReference">The expected type reference for the items in the collection.</param>
        /// <param name="listener">If not null, the reader will notify the implementer of the interface of relevant state changes in the reader.</param>
        protected ODataCollectionReaderCore(
            ODataInputContext inputContext,
            IEdmTypeReference expectedItemTypeReference,
            IODataReaderWriterListener listener)
        {
            this.inputContext = inputContext;
            this.expectedItemTypeReference = expectedItemTypeReference;

            if (this.expectedItemTypeReference == null)
            {
                // NOTE: collections cannot specify a type name for the collection itself, so always passing null.
                this.collectionValidator = new CollectionWithoutExpectedTypeValidator(/*expectedItemTypeName*/ null);
            }

            this.listener = listener;
            this.EnterScope(ODataCollectionReaderState.Start, null);
        }
        /// <summary>
        /// Asynchronously starts writing a collection - implementation of the actual functionality.
        /// </summary>
        /// <param name="collectionStart">The <see cref="ODataCollectionStart"/> representing the collection.</param>
        /// <returns>A task that represents the asynchronous write operation.</returns>
        private async Task WriteStartImplementationAsync(ODataCollectionStart collectionStart)
        {
            await this.StartPayloadInStartStateAsync()
            .ConfigureAwait(false);

            this.EnterScope(CollectionWriterState.Collection, collectionStart);
            await this.InterceptExceptionAsync(async() =>
            {
                if (this.expectedItemType == null)
                {
                    this.collectionValidator = new CollectionWithoutExpectedTypeValidator(/*expectedItemTypeName*/ null);
                }

                await this.StartCollectionAsync(collectionStart)
                .ConfigureAwait(false);
            }).ConfigureAwait(false);
        }