/// <summary>
        /// Replaces the null property instance with a more specific type
        /// </summary>
        /// <param name="payloadElement">The payload element to potentially replace</param>
        /// <returns>The original element or a copy to replace it with</returns>
        public override ODataPayloadElement Visit(NullPropertyInstance payloadElement)
        {
            ExceptionUtilities.CheckArgumentNotNull(payloadElement, "payloadElement");

            var memberPropertyAnnotation = payloadElement.Annotations.OfType <MemberPropertyAnnotation>().SingleOrDefault();

            if (memberPropertyAnnotation != null)
            {
                var memberProperty = memberPropertyAnnotation.Property;
                ExceptionUtilities.CheckObjectNotNull(memberProperty, "Member property annotation was null");

                var primitiveType = memberProperty.PropertyType as PrimitiveDataType;
                if (primitiveType != null)
                {
                    return(payloadElement.ReplaceWith(new PrimitiveProperty(payloadElement.Name, payloadElement.FullTypeName, null)));
                }

                var complexType = memberProperty.PropertyType as ComplexDataType;
                if (complexType != null)
                {
                    return(payloadElement.ReplaceWith(new ComplexProperty(payloadElement.Name, new ComplexInstance(payloadElement.FullTypeName, true))));
                }

                var collectionType = memberProperty.PropertyType as CollectionDataType;
                ExceptionUtilities.CheckObjectNotNull(collectionType, "Property type was not primitive, complex, or collection");

                primitiveType = collectionType.ElementDataType as PrimitiveDataType;
                if (primitiveType != null)
                {
                    return(payloadElement.ReplaceWith(new PrimitiveMultiValueProperty(payloadElement.Name, new PrimitiveMultiValue(payloadElement.FullTypeName, true))));
                }

                complexType = collectionType.ElementDataType as ComplexDataType;
                ExceptionUtilities.CheckObjectNotNull(complexType, "Collection element type was not primitive or complex");
                return(payloadElement.ReplaceWith(new ComplexMultiValueProperty(payloadElement.Name, new ComplexMultiValue(payloadElement.FullTypeName, true))));
            }

            var navigationPropertyAnnotation = payloadElement.Annotations.OfType <NavigationPropertyAnnotation>().SingleOrDefault();

            if (navigationPropertyAnnotation == null)
            {
                return(payloadElement);
            }

            return(payloadElement.ReplaceWith(new NavigationPropertyInstance(payloadElement.Name, new ExpandedLink())));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Visits the children of the given payload element and replaces it with a copy if any child changes
        /// </summary>
        /// <param name="payloadElement">The payload element to potentially replace</param>
        /// <returns>The original element or a copy to replace it with</returns>
        public virtual ODataPayloadElement Visit(NullPropertyInstance payloadElement)
        {
            ExceptionUtilities.CheckArgumentNotNull(payloadElement, "payloadElement");
            if (this.alwaysReplace)
            {
                return(payloadElement.ReplaceWith(new NullPropertyInstance(payloadElement.Name, payloadElement.FullTypeName)));
            }

            return(payloadElement);
        }
        /// <summary>
        /// Replaces the null property instance with a more specific type
        /// </summary>
        /// <param name="payloadElement">The payload element to potentially replace</param>
        /// <returns>The original element or a copy to replace it with</returns>
        public override ODataPayloadElement Visit(NullPropertyInstance payloadElement)
        {
            ExceptionUtilities.CheckArgumentNotNull(payloadElement, "payloadElement");

            var memberPropertyAnnotation = payloadElement.Annotations.OfType<MemberPropertyAnnotation>().SingleOrDefault();
            if (memberPropertyAnnotation != null)
            {
                var memberProperty = memberPropertyAnnotation.Property;
                ExceptionUtilities.CheckObjectNotNull(memberProperty, "Member property annotation was null");

                var primitiveType = memberProperty.PropertyType as PrimitiveDataType;
                if (primitiveType != null)
                {
                    return payloadElement.ReplaceWith(new PrimitiveProperty(payloadElement.Name, payloadElement.FullTypeName, null));
                }

                var complexType = memberProperty.PropertyType as ComplexDataType;
                if (complexType != null)
                {
                    return payloadElement.ReplaceWith(new ComplexProperty(payloadElement.Name, new ComplexInstance(payloadElement.FullTypeName, true)));
                }

                var collectionType = memberProperty.PropertyType as CollectionDataType;
                ExceptionUtilities.CheckObjectNotNull(collectionType, "Property type was not primitive, complex, or collection");

                primitiveType = collectionType.ElementDataType as PrimitiveDataType;
                if (primitiveType != null)
                {
                    return payloadElement.ReplaceWith(new PrimitiveMultiValueProperty(payloadElement.Name, new PrimitiveMultiValue(payloadElement.FullTypeName, true)));
                }

                complexType = collectionType.ElementDataType as ComplexDataType;
                ExceptionUtilities.CheckObjectNotNull(complexType, "Collection element type was not primitive or complex");
                return payloadElement.ReplaceWith(new ComplexMultiValueProperty(payloadElement.Name, new ComplexMultiValue(payloadElement.FullTypeName, true)));
            }

            var navigationPropertyAnnotation = payloadElement.Annotations.OfType<NavigationPropertyAnnotation>().SingleOrDefault();
            if (navigationPropertyAnnotation == null)
            {
                return payloadElement;
            }

            return payloadElement.ReplaceWith(new NavigationPropertyInstance(payloadElement.Name, new ExpandedLink()));
        }