/// <summary> /// Helper method for visiting collections /// </summary> /// <param name="payloadElement">The collection to visit</param> protected override void VisitCollection(ODataPayloadElementCollection payloadElement) { ExceptionUtilities.CheckArgumentNotNull(payloadElement, "payloadElement"); var enumerable = payloadElement as IEnumerable; if (enumerable != null) { foreach (var element in enumerable.Cast<ODataPayloadElement>()) { this.withinCollection = true; this.Recurse(element); } } this.withinCollection = false; }
/// <summary> /// Helper method for visiting collections /// </summary> /// <param name="payloadElement">The collection to visit</param> protected override void VisitCollection(ODataPayloadElementCollection payloadElement) { ExceptionUtilities.CheckArgumentNotNull(payloadElement, "payloadElement"); var dataType = this.MetadataStack.Peek() as CollectionDataType; if (dataType != null) { ExceptionUtilities.CheckObjectNotNull(dataType, "Expected collection data type, got '{0}'", this.MetadataStack.Peek()); payloadElement.AddAnnotationIfNotExist(new DataTypeAnnotation() { DataType = dataType }); try { this.MetadataStack.Push(dataType.ElementDataType); base.VisitCollection(payloadElement); } finally { this.MetadataStack.Pop(); } } else { var entitySet = this.MetadataStack.Peek() as EntitySet; ExceptionUtilities.CheckObjectNotNull(entitySet, "Expected entity set, got '{0}'", this.MetadataStack.Peek()); payloadElement.Add(new EntitySetAnnotation() { EntitySet = entitySet }); base.VisitCollection(payloadElement); } }
private void AddExpectedFunctionImportToCollection(ODataPayloadElementCollection collection) { var expectedTypeAnnotation = collection.GetAnnotation<ExpectedTypeODataPayloadElementAnnotation>(); if (expectedTypeAnnotation == null) { expectedTypeAnnotation = new ExpectedTypeODataPayloadElementAnnotation(); collection.Add(expectedTypeAnnotation); } if (expectedTypeAnnotation.ProductFunctionImport == null) { var typeAnnotation = collection.GetAnnotation<EntityModelTypeAnnotation>(); var collectionType = typeAnnotation.EdmModelType; if (this.testDescriptor.PayloadEdmModel != null) { EdmModel model = this.testDescriptor.PayloadEdmModel as EdmModel; EdmEntityContainer container = model.EntityContainer as EdmEntityContainer; var functionImport = container.OperationImports().FirstOrDefault(f => { return f.Operation.ReturnType != null && f.Operation.ReturnType == collectionType; }); if (functionImport == null) { functionImport = container.OperationImports().FirstOrDefault(f => { return f.Operation.ReturnType != null && f.Operation.ReturnType.IsCollection(); }); if (functionImport == null) { var collectionNameAnnotation = collection.GetAnnotation<CollectionNameAnnotation>(); container.AddFunctionAndFunctionImport(model, collectionNameAnnotation == null ? "NewFunctionImport" : collectionNameAnnotation.Name, collectionType); this.testDescriptor.ResetCachedModel(); } } expectedTypeAnnotation.ProductFunctionImport = functionImport as EdmOperationImport; } } }
/// <summary> /// Helper method for visiting collections /// </summary> /// <param name="payloadElement">The collection to visit</param> protected override void VisitCollection(ODataPayloadElementCollection payloadElement) { ExceptionUtilities.CheckArgumentNotNull(payloadElement, "payloadElement"); this.IncreaseVersionIfTrue(payloadElement.Annotations.OfType<JsonCollectionResultWrapperAnnotation>().Any(a => a.Value), DataServiceProtocolVersion.V4); base.VisitCollection(payloadElement); }
/// <summary> /// Helper method for visiting collections /// </summary> /// <param name="payloadElement">The collection to visit</param> protected override void VisitCollection(ODataPayloadElementCollection payloadElement) { ExceptionUtilities.CheckArgumentNotNull(payloadElement, "payloadElement"); var enumerable = payloadElement as IEnumerable; if (enumerable != null) { var elements = enumerable.Cast<ODataPayloadElement>().ToList(); if (elements.Count == 0) { this.AddValue(EmptyData.Value); } else { for (int i = 0; i < elements.Count; i++) { using (new DelegateBasedDisposable(() => this.currentPath.Pop())) { this.currentPath.Push(i.ToString(CultureInfo.InvariantCulture)); this.Recurse(elements[i]); } } } } }