private ODataResponse ReadResponse(ODataCollectionReader odataReader)
        {
            var collection = new List<object>();

            while (odataReader.Read())
            {
                if (odataReader.State == ODataCollectionReaderState.Completed)
                    break;

                switch (odataReader.State)
                {
                    case ODataCollectionReaderState.CollectionStart:
                        break;

                    case ODataCollectionReaderState.Value:
                        collection.Add(GetPropertyValue(odataReader.Item));
                        break;

                    case ODataCollectionReaderState.CollectionEnd:
                        break;
                }
            }

            return ODataResponse.FromCollection(collection);
        }
        internal static ODataCollectionValue ReadCollection(ODataCollectionReader reader)
        {
            ArrayList items = new ArrayList();
            string typeName = null;

            while (reader.Read())
            {
                if (ODataCollectionReaderState.Value == reader.State)
                {
                    items.Add(reader.Item);
                }
                else if (ODataCollectionReaderState.CollectionStart == reader.State)
                {
                    typeName = reader.Item.ToString();
                }
            }

            return new ODataCollectionValue { Items = items, TypeName = typeName };
        }
            /// <summary>
            /// Read a collection as the message content.
            /// </summary>
            /// <param name="collectionReader">The collection reader to use for reading.</param>
            /// <returns>An <see cref="ODataCollectionStart"/>, possibly with annotations.</returns>
            public object ReadCollection(ODataCollectionReader collectionReader)
            {
                try
                {
                    // read the start of the collection
                    collectionReader.Read();
                    this.assert.AreEqual(ODataCollectionReaderState.CollectionStart, collectionReader.State, "Reader states don't match.");

                    // NOTE: collection names are only present in ATOM; for JSON the name will be 'null'
                    ODataCollectionStart collectionStart = (ODataCollectionStart)collectionReader.Item;

                    ODataCollectionItemsObjectModelAnnotation itemsAnnotation = new ODataCollectionItemsObjectModelAnnotation();
                    while (collectionReader.Read())
                    {
                        if (collectionReader.State == ODataCollectionReaderState.Value)
                        {
                            object item = collectionReader.Item;
                            itemsAnnotation.Add(item);
                        }
                        else
                        {
                            break;
                        }
                    }

                    this.assert.AreEqual(ODataCollectionReaderState.CollectionEnd, collectionReader.State, "Reader states don't match.");

                    collectionReader.Read();
                    this.assert.AreEqual(ODataCollectionReaderState.Completed, collectionReader.State, "Reader states don't match.");

                    // attach the items to the collection and return it
                    collectionStart.SetAnnotation(itemsAnnotation);

                    return collectionStart;
                }
                catch (Exception e)
                {
                    if (ExceptionUtilities.IsCatchable(e))
                    {
                        this.assert.AreEqual(ODataCollectionReaderState.Exception, collectionReader.State, "Expected the reader to be in 'Exception' state.");
                    }

                    throw;
                }
            }
        public static ODataCollectionValue ReadCollectionParameterValue(ODataCollectionReader collectionReader)
        {
            List<object> collectionItems = new List<object>();
            while (collectionReader.Read())
            {
                if (collectionReader.State == ODataCollectionReaderState.Completed)
                {
                    break;
                }

                if (collectionReader.State == ODataCollectionReaderState.Value)
                {
                    collectionItems.Add(collectionReader.Item);
                }
            }

            ODataCollectionValue result = new ODataCollectionValue();
            result.Items = collectionItems;
            return result;
        }
        /// <summary>
        /// Reads the items from a collection and return it as an ODataCollectionValue.
        /// </summary>
        /// <param name="collectionReader">Collection reader to read from.</param>
        /// <returns>An ODataCollectionValue instance containing all items in the collection.</returns>
        private static ODataCollectionValue ReadCollectionParameterValue(ODataCollectionReader collectionReader)
        {
            Debug.Assert(collectionReader != null, "collectionReader != null");
            Debug.Assert(collectionReader.State == ODataCollectionReaderState.Start, "The collection reader should not have been used.");

            List<object> collectionItems = new List<object>();
            while (collectionReader.Read())
            {
                if (collectionReader.State == ODataCollectionReaderState.Completed)
                {
                    break;
                }

                switch (collectionReader.State)
                {
                    case ODataCollectionReaderState.CollectionStart:
                    case ODataCollectionReaderState.CollectionEnd:
                        break;

                    case ODataCollectionReaderState.Value:
                        collectionItems.Add(collectionReader.Item);
                        break;

                    default:
                        Debug.Assert(false, "Unreachable code path in ReadCollectionParameterValue().");
                        throw new InvalidOperationException(Microsoft.OData.Service.Strings.DataServiceException_GeneralError);
                }
            }

            ODataCollectionValue result = new ODataCollectionValue();
            result.Items = collectionItems;
            return result;
        }