예제 #1
0
 private static ODataCollectionValue ReadCollectionParameterValue(ODataCollectionReader collectionReader)
 {
     ODataCollectionValue value2;
     List<object> list = new List<object>();
     while (collectionReader.Read())
     {
         switch (collectionReader.State)
         {
             case ODataCollectionReaderState.CollectionStart:
             case ODataCollectionReaderState.CollectionEnd:
             {
                 continue;
             }
             case ODataCollectionReaderState.Value:
             {
                 list.Add(collectionReader.Item);
                 continue;
             }
             case ODataCollectionReaderState.Completed:
                 goto Label_004F;
         }
         throw new InvalidOperationException(System.Data.Services.Strings.DataServiceException_GeneralError);
     }
 Label_004F:
     value2 = new ODataCollectionValue();
     value2.Items = list;
     return value2;
 }
        private object Convert(ODataCollectionReader reader, IEdmCollectionTypeReference collectionType, ODataDeserializerContext readContext)
        {
            IEdmTypeReference elementType = collectionType.ElementType();
            Type clrElementType = EdmLibHelpers.GetClrType(elementType, readContext.Model);
            IList list = Activator.CreateInstance(typeof(List<>).MakeGenericType(clrElementType)) as IList;

            while (reader.Read())
            {
                switch (reader.State)
                {
                    case ODataCollectionReaderState.Value:
                        object element = Convert(reader.Item, elementType, readContext);
                        list.Add(element);
                        break;

                    default:
                        break;
                }
            }
            return list;
        }
        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 };
        }
        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);
        }