public QueryCompositionOperationInvoker(IOperationInvoker invoker, IQueryComposer queryComposer) { this.inner = invoker; this.composer = queryComposer; }
private void AddQueryComposer(DispatchOperation dispatchOperation, OperationDescription operationDescription, bool isAttributeSetOnOperation) { // QueryComposer is added for 2-way operations when the returnType is IEnumerable, IEnumerable<>, IQueryable or IQueryable<> // if enabled and the user did not specify the queryComposerType, add the UrlQueryComposerType if (dispatchOperation.IsOneWay) { if (isAttributeSetOnOperation && this.enabled) { // throw if the QueryCompositionAttribute was set on the Operation throw new InvalidOperationException(String.Format( CultureInfo.InvariantCulture, "QueryComposition attribute was set on one-way operation {0}. Please remove this attribute from this operation.", dispatchOperation.Name)); } return; } else { // Verify if the returnType type is IEnumerable, IEnumerable<>, IQueryable or IQueryable<> bool isQueryCompositionSupportedOnReturnType = false; Type returnType = null; if (operationDescription.Messages[1] != null && operationDescription.Messages[1].Body != null && operationDescription.Messages[1].Body.ReturnValue != null) { returnType = operationDescription.Messages[1].Body.ReturnValue.Type; if (returnType != null) { if (returnType == EnumerableType) { isQueryCompositionSupportedOnReturnType = true; } else if (returnType.IsGenericType) { Type genericTypeDefinition = returnType.GetGenericTypeDefinition(); if (genericTypeDefinition == GenericEnumerableType) { isQueryCompositionSupportedOnReturnType = true; } //FIX: GB - IQueryable else if (genericTypeDefinition == GenericQueryableType) { isQueryCompositionSupportedOnReturnType = true; } } } } // if the returnType is not IEnumerable, IEnumerable<>, we don't set the QueryComposer if (!isQueryCompositionSupportedOnReturnType) { // throw if the QueryCompositionAttribute was set on the Operation if (isAttributeSetOnOperation && this.enabled) { throw new InvalidOperationException( String.Format( CultureInfo.InvariantCulture, "QueryComposition attribute was set on operation {0}, but the return type is not defined as IEnumerable. Please remove this attribute from this operation or change the operation return type to IEnumerable", dispatchOperation.Name)); } return; } if (this.enabled) { IQueryComposer queryComposer = null; if (this.queryComposerType == null) { queryComposer = new UrlQueryComposer(); } else { queryComposer = (IQueryComposer)Activator.CreateInstance(this.queryComposerType); } dispatchOperation.Invoker = new QueryCompositionOperationInvoker(dispatchOperation.Invoker, queryComposer); } } }