private static ReadOnlyCollection <OperationParameter> ValidateParameters(System.Data.Services.Providers.OperationParameterBindingKind operationParameterBindingKind, IEnumerable <OperationParameter> parameters) { if (parameters == null) { return(OperationParameter.EmptyOperationParameterCollection); } ReadOnlyCollection <OperationParameter> onlys = new ReadOnlyCollection <OperationParameter>(new List <OperationParameter>(parameters)); HashSet <string> set = new HashSet <string>(StringComparer.Ordinal); int num = (operationParameterBindingKind != System.Data.Services.Providers.OperationParameterBindingKind.Never) ? 0 : -1; for (int i = 0; i < onlys.Count; i++) { OperationParameter parameter = onlys[i]; if (!set.Add(parameter.Name)) { throw new ArgumentException(System.Data.Services.Strings.ServiceOperation_DuplicateParameterName(parameter.Name), "parameters"); } if (i > num) { ResourceTypeKind resourceTypeKind = parameter.ParameterType.ResourceTypeKind; switch (resourceTypeKind) { case ResourceTypeKind.EntityType: case ResourceTypeKind.EntityCollection: throw new ArgumentException(System.Data.Services.Strings.ServiceOperation_NonBindingParametersCannotBeEntityorEntityCollection(parameter.Name, resourceTypeKind)); } } } return(onlys); }
internal Operation(string name, ServiceOperationResultKind resultKind, ResourceType returnType, System.Data.Services.Providers.ResourceSet resultSet, ResourceSetPathExpression resultSetPathExpression, string method, IEnumerable<OperationParameter> parameters, System.Data.Services.Providers.OperationParameterBindingKind operationParameterBindingKind, OperationKind kind) { WebUtil.CheckStringArgumentNullOrEmpty(name, "name"); WebUtil.CheckServiceOperationResultKind(resultKind, "resultKind"); WebUtil.CheckStringArgumentNullOrEmpty(method, "method"); ValidateConstructorArguments(name, returnType, resultSet, resultSetPathExpression, method, operationParameterBindingKind, kind); this.name = name; this.resultKind = resultKind; this.returnType = returnType; this.resourceSet = resultSet; this.resultSetPathExpression = resultSetPathExpression; this.method = method; this.kind = kind; this.operationParameterBindingKind = operationParameterBindingKind; this.operationParameters = ValidateParameters(this.operationParameterBindingKind, parameters); if (this.operationParameterBindingKind != System.Data.Services.Providers.OperationParameterBindingKind.Never) { this.bindingParameter = this.operationParameters.FirstOrDefault<OperationParameter>(); if (this.bindingParameter == null) { throw new ArgumentException(System.Data.Services.Strings.ServiceOperation_BindableOperationMustHaveAtLeastOneParameter, "operationParameterBindingKind"); } if (((resultSetPathExpression != null) && (this.bindingParameter.ParameterType.ResourceTypeKind != ResourceTypeKind.EntityType)) && (this.bindingParameter.ParameterType.ResourceTypeKind != ResourceTypeKind.EntityCollection)) { throw new ArgumentException(System.Data.Services.Strings.ServiceOperation_BindingParameterMustBeEntityToUsePathExpression("resultSetPathExpression")); } if (((this.kind == OperationKind.Action) && (this.bindingParameter.ParameterType.ResourceTypeKind != ResourceTypeKind.EntityType)) && (this.bindingParameter.ParameterType.ResourceTypeKind != ResourceTypeKind.EntityCollection)) { throw new ArgumentException(System.Data.Services.Strings.ServiceOperation_ActionBindingMustBeEntityOrEntityCollection, "parameters"); } if (this.resultSetPathExpression != null) { this.resultSetPathExpression.SetBindingParameter(this.bindingParameter); } } }
internal Operation(string name, ServiceOperationResultKind resultKind, ResourceType returnType, System.Data.Services.Providers.ResourceSet resultSet, ResourceSetPathExpression resultSetPathExpression, string method, IEnumerable <OperationParameter> parameters, System.Data.Services.Providers.OperationParameterBindingKind operationParameterBindingKind, OperationKind kind) { WebUtil.CheckStringArgumentNullOrEmpty(name, "name"); WebUtil.CheckServiceOperationResultKind(resultKind, "resultKind"); WebUtil.CheckStringArgumentNullOrEmpty(method, "method"); ValidateConstructorArguments(name, returnType, resultSet, resultSetPathExpression, method, operationParameterBindingKind, kind); this.name = name; this.resultKind = resultKind; this.returnType = returnType; this.resourceSet = resultSet; this.resultSetPathExpression = resultSetPathExpression; this.method = method; this.kind = kind; this.operationParameterBindingKind = operationParameterBindingKind; this.operationParameters = ValidateParameters(this.operationParameterBindingKind, parameters); if (this.operationParameterBindingKind != System.Data.Services.Providers.OperationParameterBindingKind.Never) { this.bindingParameter = this.operationParameters.FirstOrDefault <OperationParameter>(); if (this.bindingParameter == null) { throw new ArgumentException(System.Data.Services.Strings.ServiceOperation_BindableOperationMustHaveAtLeastOneParameter, "operationParameterBindingKind"); } if (((resultSetPathExpression != null) && (this.bindingParameter.ParameterType.ResourceTypeKind != ResourceTypeKind.EntityType)) && (this.bindingParameter.ParameterType.ResourceTypeKind != ResourceTypeKind.EntityCollection)) { throw new ArgumentException(System.Data.Services.Strings.ServiceOperation_BindingParameterMustBeEntityToUsePathExpression("resultSetPathExpression")); } if (((this.kind == OperationKind.Action) && (this.bindingParameter.ParameterType.ResourceTypeKind != ResourceTypeKind.EntityType)) && (this.bindingParameter.ParameterType.ResourceTypeKind != ResourceTypeKind.EntityCollection)) { throw new ArgumentException(System.Data.Services.Strings.ServiceOperation_ActionBindingMustBeEntityOrEntityCollection, "parameters"); } if (this.resultSetPathExpression != null) { this.resultSetPathExpression.SetBindingParameter(this.bindingParameter); } } }
private static void ValidateConstructorArguments(string operationName, ResourceType returnType, System.Data.Services.Providers.ResourceSet resultSet, ResourceSetPathExpression resultSetPathExpression, string method, System.Data.Services.Providers.OperationParameterBindingKind operationParameterBindingKind, OperationKind kind) { if ((returnType != null) && ((returnType.ResourceTypeKind == ResourceTypeKind.EntityType) || (returnType.ResourceTypeKind == ResourceTypeKind.EntityCollection))) { ResourceType subType = (returnType.ResourceTypeKind == ResourceTypeKind.EntityCollection) ? ((EntityCollectionResourceType)returnType).ItemType : returnType; if (((resultSet == null) && (resultSetPathExpression == null)) || ((resultSet != null) && !resultSet.ResourceType.IsAssignableFrom(subType))) { if (kind == OperationKind.ServiceOperation) { throw new ArgumentException(System.Data.Services.Strings.ServiceOperation_ResultTypeAndResultSetMustMatch("resultType", "resultSet")); } throw new ArgumentException(System.Data.Services.Strings.ServiceOperation_ReturnTypeAndResultSetMustMatch("returnType", "resultSetPathExpression", "resultSet")); } } else if ((resultSet != null) || (resultSetPathExpression != null)) { string str = (resultSet != null) ? "resultSet" : "resultSetPathExpression"; if (kind == OperationKind.ServiceOperation) { throw new ArgumentException(System.Data.Services.Strings.ServiceOperation_ResultSetMustBeNullForGivenResultType(str, "resultType")); } throw new ArgumentException(System.Data.Services.Strings.ServiceOperation_ResultSetMustBeNullForGivenReturnType(str, "returnType")); } if ((returnType != null) && (returnType == ResourceType.GetPrimitiveResourceType(typeof(Stream)))) { string str2; string str3; if (kind == OperationKind.ServiceOperation) { str2 = "resultType"; str3 = System.Data.Services.Strings.ServiceOperation_InvalidResultType(returnType.FullName); } else { str2 = "returnType"; str3 = System.Data.Services.Strings.ServiceOperation_InvalidReturnType(returnType.FullName); } throw new ArgumentException(str3, str2); } if ((string.CompareOrdinal("GET", method) != 0) && (string.CompareOrdinal("POST", method) != 0)) { throw new ArgumentException(System.Data.Services.Strings.ServiceOperation_NotSupportedProtocolMethod(method, operationName), "method"); } if ((resultSetPathExpression != null) && (operationParameterBindingKind == System.Data.Services.Providers.OperationParameterBindingKind.Never)) { throw new ArgumentException(System.Data.Services.Strings.ServiceOperation_MustBeBindableToUsePathExpression("resultSetPathExpression"), "resultSetPathExpression"); } }