Exemplo n.º 1
0
            /// <summary>
            /// Visits a collection start.
            /// </summary>
            /// <param name="collection">The collection start to visit.</param>
            protected override ODataPayloadElement VisitCollectionStart(ODataCollectionStart collection)
            {
                ExceptionUtilities.CheckArgumentNotNull(collection, "collection");

                // NOTE the Taupo OM does not currently support heterogenous collections; we determine the
                //      type of the collection by looking at the first non-null item
                ODataCollectionItemsObjectModelAnnotation itemsAnnotation = collection.GetAnnotation <ODataCollectionItemsObjectModelAnnotation>();

                ExceptionUtilities.Assert(itemsAnnotation != null, "itemsAnnotation != null");

                // NOTE we assume that it is a primitive collection; if we find a collection of only null items we treat it as primitive
                bool isComplexCollection = false;

                foreach (object item in itemsAnnotation)
                {
                    if (item != null)
                    {
                        isComplexCollection = item is ODataComplexValue;
                        break;
                    }
                }

                if (isComplexCollection)
                {
                    ComplexInstanceCollection complexCollection = PayloadBuilder.ComplexCollection(collection.Name);

                    foreach (object item in itemsAnnotation)
                    {
                        ComplexInstance complexInstance = item == null
                            ? new ComplexInstance(null, /*isNull*/ true)
                            : (ComplexInstance)this.Visit((ODataComplexValue)item);
                        complexCollection.Add(complexInstance);
                    }

                    return(complexCollection);
                }
                else
                {
                    PrimitiveCollection primitiveCollection = PayloadBuilder.PrimitiveCollection(collection.Name);

                    foreach (object item in itemsAnnotation)
                    {
                        PrimitiveValue primitiveValue = (PrimitiveValue)this.Visit(item);
                        primitiveCollection.Add(primitiveValue);
                    }

                    return(primitiveCollection);
                }
            }
Exemplo n.º 2
0
            /// <summary>
            /// Visits a collection start.
            /// </summary>
            /// <param name="collection">The collection start to visit.</param>
            protected override ODataPayloadElement VisitCollectionStart(ODataCollectionStart collection)
            {
                ExceptionUtilities.CheckArgumentNotNull(collection, "collection");

                // NOTE the Taupo OM does not currently support heterogenous collections; we determine the
                //      type of the collection by looking at the first non-null item
                ODataCollectionItemsObjectModelAnnotation itemsAnnotation = collection.GetAnnotation <ODataCollectionItemsObjectModelAnnotation>();

                ExceptionUtilities.Assert(itemsAnnotation != null, "itemsAnnotation != null");

                PrimitiveCollection primitiveCollection = PayloadBuilder.PrimitiveCollection(collection.Name);

                foreach (object item in itemsAnnotation)
                {
                    PrimitiveValue primitiveValue = (PrimitiveValue)this.Visit(item);
                    primitiveCollection.Add(primitiveValue);
                }

                return(primitiveCollection);
            }