/// <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(EmptyUntypedCollection payloadElement) { ExceptionUtilities.CheckArgumentNotNull(payloadElement, "payloadElement"); if (this.alwaysReplace) { return(payloadElement.ReplaceWith(new EmptyUntypedCollection())); } return(payloadElement); }
/// <summary> /// Replaces the empty collection property 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(EmptyUntypedCollection payloadElement) { ExceptionUtilities.CheckArgumentNotNull(payloadElement, "payloadElement"); var expectedTypeAnnotatation = payloadElement.Annotations.OfType <ExpectedPayloadElementTypeAnnotation>().SingleOrDefault(); if (expectedTypeAnnotatation != null && expectedTypeAnnotatation.ExpectedType == ODataPayloadElementType.LinkCollection) { var linkCollection = new LinkCollection(); linkCollection.InlineCount = payloadElement.InlineCount; linkCollection.NextLink = payloadElement.NextLink; return(payloadElement.ReplaceWith(linkCollection)); } var entitySetAnnotation = payloadElement.Annotations.OfType <EntitySetAnnotation>().SingleOrDefault(); if (entitySetAnnotation != null) { var entitySet = new EntitySetInstance(); entitySet.InlineCount = payloadElement.InlineCount; entitySet.NextLink = payloadElement.NextLink; return(payloadElement.ReplaceWith(entitySet)); } var functionAnnotation = payloadElement.Annotations.OfType <FunctionAnnotation>().SingleOrDefault(); if (functionAnnotation != null && expectedTypeAnnotatation != null) { if (expectedTypeAnnotatation.ExpectedType == ODataPayloadElementType.ComplexInstanceCollection) { return(payloadElement.ReplaceWith(new ComplexInstanceCollection())); } if (expectedTypeAnnotatation.ExpectedType == ODataPayloadElementType.PrimitiveCollection) { return(payloadElement.ReplaceWith(new PrimitiveCollection())); } } return(base.Visit(payloadElement)); }
/// <summary> /// Replaces the empty collection property 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(EmptyUntypedCollection payloadElement) { ExceptionUtilities.CheckArgumentNotNull(payloadElement, "payloadElement"); var expectedTypeAnnotatation = payloadElement.Annotations.OfType<ExpectedPayloadElementTypeAnnotation>().SingleOrDefault(); if (expectedTypeAnnotatation != null && expectedTypeAnnotatation.ExpectedType == ODataPayloadElementType.LinkCollection) { var linkCollection = new LinkCollection(); linkCollection.InlineCount = payloadElement.InlineCount; linkCollection.NextLink = payloadElement.NextLink; return payloadElement.ReplaceWith(linkCollection); } var entitySetAnnotation = payloadElement.Annotations.OfType<EntitySetAnnotation>().SingleOrDefault(); if (entitySetAnnotation != null) { var entitySet = new EntitySetInstance(); entitySet.InlineCount = payloadElement.InlineCount; entitySet.NextLink = payloadElement.NextLink; return payloadElement.ReplaceWith(entitySet); } var functionAnnotation = payloadElement.Annotations.OfType<FunctionAnnotation>().SingleOrDefault(); if (functionAnnotation != null && expectedTypeAnnotatation != null) { if (expectedTypeAnnotatation.ExpectedType == ODataPayloadElementType.ComplexInstanceCollection) { return payloadElement.ReplaceWith(new ComplexInstanceCollection()); } if (expectedTypeAnnotatation.ExpectedType == ODataPayloadElementType.PrimitiveCollection) { return payloadElement.ReplaceWith(new PrimitiveCollection()); } } return base.Visit(payloadElement); }