internal static DbExpressionList CreateExpressionList( IEnumerable <DbExpression> arguments, string argumentName, Action <DbExpression, int> validationCallback) { return(ArgumentValidation.CreateExpressionList(arguments, argumentName, false, validationCallback)); }
internal static TypeUsage ValidateNew( TypeUsage instanceType, IEnumerable <DbExpression> arguments, out DbExpressionList validArguments) { ArgumentValidation.CheckType(instanceType, nameof(instanceType)); CollectionType type = (CollectionType)null; if (TypeHelpers.TryGetEdmType <CollectionType>(instanceType, out type) && type != null) { TypeUsage elementType = type.TypeUsage; validArguments = ArgumentValidation.CreateExpressionList(arguments, nameof(arguments), true, (Action <DbExpression, int>)((exp, idx) => ArgumentValidation.RequireCompatibleType(exp, elementType, nameof(arguments), idx))); } else { List <TypeUsage> expectedTypes = ArgumentValidation.GetStructuralMemberTypes(instanceType); int pos = 0; validArguments = ArgumentValidation.CreateExpressionList(arguments, nameof(arguments), expectedTypes.Count, (Action <DbExpression, int>)((exp, idx) => ArgumentValidation.RequireCompatibleType(exp, expectedTypes[pos++], nameof(arguments), idx))); } return(instanceType); }
internal static DbExpressionList ValidateFunctionAggregate( EdmFunction function, IEnumerable <DbExpression> args) { ArgumentValidation.CheckFunction(function); if (!TypeSemantics.IsAggregateFunction(function) || function.ReturnParameter == null) { throw new ArgumentException(Strings.Cqt_Aggregate_InvalidFunction, nameof(function)); } FunctionParameter[] expectedParams = ArgumentValidation.GetExpectedParameters(function); return(ArgumentValidation.CreateExpressionList(args, "argument", expectedParams.Length, (Action <DbExpression, int>)((exp, idx) => { TypeUsage typeUsage = expectedParams[idx].TypeUsage; TypeUsage elementType = (TypeUsage)null; if (TypeHelpers.TryGetCollectionElementType(typeUsage, out elementType)) { typeUsage = elementType; } ArgumentValidation.RequireCompatibleType(exp, typeUsage, "argument"); }))); }
internal static TypeUsage ValidateFunction( EdmFunction function, IEnumerable <DbExpression> arguments, out DbExpressionList validArgs) { ArgumentValidation.CheckFunction(function); if (!function.IsComposableAttribute) { throw new ArgumentException(Strings.Cqt_Function_NonComposableInExpression, nameof(function)); } if (!string.IsNullOrEmpty(function.CommandTextAttribute) && !function.HasUserDefinedBody) { throw new ArgumentException(Strings.Cqt_Function_CommandTextInExpression, nameof(function)); } if (function.ReturnParameter == null) { throw new ArgumentException(Strings.Cqt_Function_VoidResultInvalid, nameof(function)); } FunctionParameter[] expectedParams = ArgumentValidation.GetExpectedParameters(function); validArgs = ArgumentValidation.CreateExpressionList(arguments, nameof(arguments), expectedParams.Length, (Action <DbExpression, int>)((exp, idx) => ArgumentValidation.RequireCompatibleType(exp, expectedParams[idx].TypeUsage, nameof(arguments), idx))); return(function.ReturnParameter.TypeUsage); }
internal static TypeUsage ValidateCase( IEnumerable <DbExpression> whenExpressions, IEnumerable <DbExpression> thenExpressions, DbExpression elseExpression, out DbExpressionList validWhens, out DbExpressionList validThens) { validWhens = ArgumentValidation.CreateExpressionList(whenExpressions, nameof(whenExpressions), (Action <DbExpression, int>)((exp, idx) => ArgumentValidation.RequireCompatibleType(exp, PrimitiveTypeKind.Boolean, nameof(whenExpressions), idx))); TypeUsage commonResultType = (TypeUsage)null; validThens = ArgumentValidation.CreateExpressionList(thenExpressions, nameof(thenExpressions), (Action <DbExpression, int>)((exp, idx) => { if (commonResultType == null) { commonResultType = exp.ResultType; } else { commonResultType = TypeHelpers.GetCommonTypeUsage(exp.ResultType, commonResultType); if (commonResultType == null) { throw new ArgumentException(Strings.Cqt_Case_InvalidResultType); } } })); commonResultType = TypeHelpers.GetCommonTypeUsage(elseExpression.ResultType, commonResultType); if (commonResultType == null) { throw new ArgumentException(Strings.Cqt_Case_InvalidResultType); } if (validWhens.Count != validThens.Count) { throw new ArgumentException(Strings.Cqt_Case_WhensMustEqualThens); } return(commonResultType); }