Ejemplo n.º 1
0
            /// <summary>
            /// Visits a collection of parameters.
            /// </summary>
            /// <param name="parameters">The parameters to visit.</param>
            protected override ODataPayloadElement VisitParameters(ODataParameters parameters)
            {
                ExceptionUtilities.CheckArgumentNotNull(parameters, "parameters");
                ComplexInstance result = new ComplexInstance();

                result.IsNull = parameters.Count == 0;
                foreach (var parameter in parameters)
                {
                    if (parameter.Value == null)
                    {
                        result.Add(new PrimitiveProperty(parameter.Key, null, null));
                        continue;
                    }

                    ODataComplexValue    odataComplexValue    = parameter.Value as ODataComplexValue;
                    ODataCollectionStart odataCollectionStart = parameter.Value as ODataCollectionStart;

                    if (odataCollectionStart != null)
                    {
                        ODataCollectionItemsObjectModelAnnotation annotation = odataCollectionStart.GetAnnotation <ODataCollectionItemsObjectModelAnnotation>();
                        if (annotation.OfType <ODataComplexValue>().FirstOrDefault() != null)
                        {
                            ComplexMultiValue complexCollection = PayloadBuilder.ComplexMultiValue();
                            foreach (var value in annotation)
                            {
                                complexCollection.Item(this.VisitComplexValue(value as ODataComplexValue) as ComplexInstance);
                            }

                            ComplexMultiValueProperty complexCollectionProperty = new ComplexMultiValueProperty(parameter.Key, complexCollection);
                            result.Add(complexCollectionProperty);
                        }
                        else
                        {
                            PrimitiveMultiValue primitiveCollection = PayloadBuilder.PrimitiveMultiValue();
                            foreach (var value in annotation)
                            {
                                primitiveCollection.Item(value);
                            }

                            PrimitiveMultiValueProperty primitiveCollectionProperty = new PrimitiveMultiValueProperty(parameter.Key, primitiveCollection);
                            result.Add(primitiveCollectionProperty);
                        }
                    }
                    else if (odataComplexValue != null)
                    {
                        ComplexInstance complexInstance = PayloadBuilder.ComplexValue(odataComplexValue.TypeName);
                        complexInstance.IsNull = false;
                        foreach (ODataProperty odataProperty in odataComplexValue.Properties)
                        {
                            complexInstance.Property(odataProperty.Name, this.Visit(odataProperty.Value));
                        }

                        result.Add(new ComplexProperty(parameter.Key, complexInstance));
                    }
                    else
                    {
                        result.Add(new PrimitiveProperty(parameter.Key, null, PayloadBuilder.PrimitiveValue(parameter.Value).ClrValue));
                    }
                }

                return(result);
            }