Ejemplo n.º 1
0
        /// <summary>
        /// Generates System.CodeDom.CodeExpression from the given expression.
        /// </summary>
        /// <param name="expression">Expression from which System.CodeDom.CodeExpression is generated.</param>
        /// <returns>Generated System.CodeDom.CodeExpression.</returns>
        public virtual CodeExpression Visit(LinqBuiltInFunctionCallExpression expression)
        {
            CodeExpression source = null;

            var builtInFunction = expression.LinqBuiltInFunction;
            var arguments       = this.GenerateCodeForArguments(expression.Arguments).ToArray();

            if (builtInFunction.BuiltInFunctionKind == LinqBuiltInFunctionKind.InstanceMethod)
            {
                ExceptionUtilities.Assert(arguments.Length >= 1, "Wrong number of arguments");
                var args = arguments.Skip(1).ToArray();
                source = arguments[0];
                return(source.Call(builtInFunction.MethodName, args));
            }
            else if (expression.LinqBuiltInFunction.BuiltInFunctionKind == LinqBuiltInFunctionKind.InstanceProperty)
            {
                ExceptionUtilities.Assert(arguments.Length == 1, "Wrong number of arguments");
                source = arguments[0];
                return(source.Property(builtInFunction.BuiltInFunction.Name));
            }
            else
            {
                var type = new CodeTypeReferenceExpression(builtInFunction.ClassName);
                ExceptionUtilities.Assert(expression.LinqBuiltInFunction.BuiltInFunctionKind == LinqBuiltInFunctionKind.StaticMethod, "Builtin function kind {0} not supported", expression.LinqBuiltInFunction.BuiltInFunctionKind.ToString());
                return(type.Call(builtInFunction.MethodName, arguments));
            }
        }
            public override string Visit(LinqBuiltInFunctionCallExpression expression)
            {
                ExceptionUtilities.CheckArgumentNotNull(expression, "expression");

                if (expression.Arguments.Count == 0)
                {
                    throw new TaupoNotSupportedException("Not supported");
                }

                var protocolFunctionAnnotation = expression.LinqBuiltInFunction.Annotations.OfType <ODataCanonicalFunctionNameAnnotation>().SingleOrDefault();

                ExceptionUtilities.CheckObjectNotNull(protocolFunctionAnnotation, "Cannot build a uri expression for built-in function without annotation. Function was: {0}", expression.LinqBuiltInFunction.MethodName);

                string argValues = string.Empty;
                var    name      = protocolFunctionAnnotation.Name;

                if (string.Equals(name, "round", StringComparison.Ordinal))
                {
                    // because of inconsistency between the CLR Math.Round and Sql Server's Round function,
                    // we will have to enforce passing in two parameters, the second of which will be ignored when
                    // we build the Uri for the Round function call.
                    argValues = string.Join(",", expression.Arguments.Take(1).Select(a => this.Convert(a)));
                }
                else
                {
                    argValues = string.Join(",", expression.Arguments.Select(a => this.Convert(a)));
                }

                return(string.Format(CultureInfo.InvariantCulture, "{0}({1})", name, argValues));
            }
Ejemplo n.º 3
0
        /// <summary>
        /// Resolves types for the specified expression.
        /// </summary>
        /// <param name="expression">The expression to resolve types for.</param>
        /// <returns>Expression with resolved types.</returns>
        public QueryExpression Visit(LinqBuiltInFunctionCallExpression expression)
        {
            var resolvedArguemnts = this.ResolveTypesForArguments(expression.Arguments);

            var resolvedResultType = this.ResolveBuiltInFunctionResultType(expression.LinqBuiltInFunction.BuiltInFunction, resolvedArguemnts.Select(a => a.ExpressionType).ToArray());

            return(new LinqBuiltInFunctionCallExpression(resolvedResultType, expression.LinqBuiltInFunction, resolvedArguemnts));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Replaces the given expression.
        /// </summary>
        /// <param name="expression">The root node of the expression tree being visited.</param>
        /// <returns>Replaced expression.</returns>
        public virtual QueryExpression Visit(LinqBuiltInFunctionCallExpression expression)
        {
            var replacedArguments = this.ReplaceArguments(expression.Arguments);

            if (this.HasChanged(expression.Arguments.ToList(), replacedArguments))
            {
                return(new LinqBuiltInFunctionCallExpression(expression.ExpressionType, expression.LinqBuiltInFunction, replacedArguments.ToArray()));
            }
            else
            {
                return(expression);
            }
        }
Ejemplo n.º 5
0
            /// <summary>
            /// Generates System.CodeDom.CodeExpression from the given expression.
            /// </summary>
            /// <param name="expression">Expression from which System.CodeDom.CodeExpression is generated.</param>
            /// <returns>
            /// Generated System.CodeDom.CodeExpression.
            /// </returns>
            public override CodeExpression Visit(LinqBuiltInFunctionCallExpression expression)
            {
                if (expression.LinqBuiltInFunction.BuiltInFunctionKind == LinqBuiltInFunctionKind.InstanceProperty)
                {
                    var type = this.GetClrType(expression.Arguments[0]);
                    if (Nullable.GetUnderlyingType(type) != null)
                    {
                        var    instance     = this.GenerateCode(expression.Arguments[0]);
                        string propertyName = expression.LinqBuiltInFunction.MethodName;
                        return(instance.Property("Value").Property(propertyName));
                    }
                }

                return(base.Visit(expression));
            }
            public override string Visit(LinqBuiltInFunctionCallExpression expression)
            {
                ExceptionUtilities.CheckArgumentNotNull(expression, "expression");

                if (expression.Arguments.Count == 0)
                {
                    throw new TaupoNotSupportedException("Not supported");
                }

                var protocolFunctionAnnotation = expression.LinqBuiltInFunction.Annotations.OfType<ODataCanonicalFunctionNameAnnotation>().SingleOrDefault();
                ExceptionUtilities.CheckObjectNotNull(protocolFunctionAnnotation, "Cannot build a uri expression for built-in function without annotation. Function was: {0}", expression.LinqBuiltInFunction.MethodName);

                string argValues = string.Empty;
                var name = protocolFunctionAnnotation.Name;
                if (string.Equals(name, "round", StringComparison.Ordinal))
                {
                    // because of inconsistency between the CLR Math.Round and Sql Server's Round function,
                    // we will have to enforce passing in two parameters, the second of which will be ignored when
                    // we build the Uri for the Round function call.
                    argValues = string.Join(",", expression.Arguments.Take(1).Select(a => this.Convert(a)));
                }
                else
                {
                    argValues = string.Join(",", expression.Arguments.Select(a => this.Convert(a)));
                }

                return string.Format(CultureInfo.InvariantCulture, "{0}({1})", name, argValues);
            }
Ejemplo n.º 7
0
 /// <summary>
 /// Visits a QueryExpression tree whose root node is the LinqBuiltInFunctionCallExpression.
 /// </summary>
 /// <param name="expression">The root node of the expression tree being visited.</param>
 /// <returns>Uri query string representing the expression.</returns>
 public virtual string Visit(LinqBuiltInFunctionCallExpression expression)
 {
     throw new TaupoNotSupportedException("Not supported");
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Evaluates the specified expression.
 /// </summary>
 /// <param name="expression">The expression to evaluate.</param>
 /// <returns>Value of the expression.</returns>
 public virtual QueryValue Visit(LinqBuiltInFunctionCallExpression expression)
 {
     return(this.EvaluateBuiltInFunction(expression.ExpressionType, expression.LinqBuiltInFunction.BuiltInFunction, expression.Arguments));
 }