public static CheckArgumentCount ( |
||
methodCallExpression | ||
리턴 | void |
public Expression Transform(MethodCallExpression methodCallExpression) { ArgumentUtility.CheckNotNull("methodCallExpression", methodCallExpression); MethodCallTransformerUtility.CheckArgumentCount(methodCallExpression, 2); MethodCallTransformerUtility.CheckInstanceMethod(methodCallExpression); return(new SqlFunctionExpression(methodCallExpression.Type, "REPLACE", methodCallExpression.Object, methodCallExpression.Arguments[0], methodCallExpression.Arguments[1])); }
public Expression Transform(MethodCallExpression methodCallExpression) { ArgumentUtility.CheckNotNull("methodCallExpression", methodCallExpression); MethodCallTransformerUtility.CheckArgumentCount(methodCallExpression, 0); MethodCallTransformerUtility.CheckInstanceMethod(methodCallExpression); return(new SqlFunctionExpression(methodCallExpression.Type, "LOWER", methodCallExpression.Object)); }
public Expression Transform(MethodCallExpression methodCallExpression) { ArgumentUtility.CheckNotNull("methodCallExpression", methodCallExpression); MethodCallTransformerUtility.CheckArgumentCount(methodCallExpression, 1); MethodCallTransformerUtility.CheckInstanceMethod(methodCallExpression); return(SqlLikeExpression.Create(methodCallExpression.Object, methodCallExpression.Arguments[0], "%", "%")); }
public Expression Transform(MethodCallExpression methodCallExpression) { ArgumentUtility.CheckNotNull("methodCallExpression", methodCallExpression); MethodCallTransformerUtility.CheckArgumentCount(methodCallExpression, 2); MethodCallTransformerUtility.CheckStaticMethod(methodCallExpression); return(new SqlLikeExpression(methodCallExpression.Arguments[0], methodCallExpression.Arguments[1], new SqlLiteralExpression(@"\"))); }
public Expression Transform(MethodCallExpression methodCallExpression) { ArgumentUtility.CheckNotNull("methodCallExpression", methodCallExpression); MethodCallTransformerUtility.CheckArgumentCount(methodCallExpression, 1); MethodCallTransformerUtility.CheckInstanceMethod(methodCallExpression); switch (methodCallExpression.Method.Name) { case "Add": Trace.Assert(methodCallExpression.Method.Name == "Add"); var constantTimeSpanExpression = methodCallExpression.Arguments[0] as ConstantExpression; if (constantTimeSpanExpression == null) { var message = string.Format( "The method 'System.DateTime.Add' can only be transformed to SQL when its argument is a constant value. Expression: '{0}'.", methodCallExpression); throw new NotSupportedException(message); } return(AddTimeSpan((TimeSpan)constantTimeSpanExpression.Value, methodCallExpression.Object)); case "AddDays": return(AddWithConversion( methodCallExpression.Arguments[0], TimeSpan.TicksPerDay / TimeSpan.TicksPerMillisecond, methodCallExpression.Object)); case "AddHours": return(AddWithConversion( methodCallExpression.Arguments[0], TimeSpan.TicksPerHour / TimeSpan.TicksPerMillisecond, methodCallExpression.Object)); case "AddMilliseconds": return(AddMilliseconds(methodCallExpression.Arguments[0], methodCallExpression.Object)); case "AddMinutes": return(AddWithConversion( methodCallExpression.Arguments[0], TimeSpan.TicksPerMinute / TimeSpan.TicksPerMillisecond, methodCallExpression.Object)); case "AddMonths": return(AddUnits(methodCallExpression.Arguments[0], "month", methodCallExpression.Object)); case "AddSeconds": return(AddWithConversion( methodCallExpression.Arguments[0], TimeSpan.TicksPerSecond / TimeSpan.TicksPerMillisecond, methodCallExpression.Object)); case "AddTicks": return(AddTicks(methodCallExpression.Arguments[0], methodCallExpression.Object)); case "AddYears": return(AddUnits(methodCallExpression.Arguments[0], "year", methodCallExpression.Object)); default: var argumentExceptionMessage = string.Format( "The method '{0}.{1}' is not a supported method.", methodCallExpression.Method.DeclaringType, methodCallExpression.Method.Name); throw new ArgumentException(argumentExceptionMessage, "methodCallExpression"); } }
public Expression Transform(MethodCallExpression methodCallExpression) { ArgumentUtility.CheckNotNull("methodCallExpression", methodCallExpression); MethodCallTransformerUtility.CheckArgumentCount(methodCallExpression, 1); MethodCallTransformerUtility.CheckStaticMethod(methodCallExpression); return(new SqlConvertExpression(methodCallExpression.Type, methodCallExpression.Arguments[0])); }
public Expression Transform(MethodCallExpression methodCallExpression) { ArgumentUtility.CheckNotNull("methodCallExpression", methodCallExpression); MethodCallTransformerUtility.CheckArgumentCount(methodCallExpression, 1); MethodCallTransformerUtility.CheckStaticMethod(methodCallExpression); var isNullExpression = new SqlIsNullExpression(methodCallExpression.Arguments[0]); var lenExpression = new SqlLengthExpression(methodCallExpression.Arguments[0]); var lenIsZeroExpression = Expression.Equal(lenExpression, new SqlLiteralExpression(0)); return(Expression.OrElse(isNullExpression, lenIsZeroExpression)); }
public Expression Transform(MethodCallExpression methodCallExpression) { MethodCallTransformerUtility.CheckArgumentCount(methodCallExpression, 2, 3); MethodCallTransformerUtility.CheckStaticMethod(methodCallExpression); if (methodCallExpression.Arguments.Count == 2) // overload without language { return(new SqlFunctionExpression(typeof(bool), "CONTAINS", methodCallExpression.Arguments[0], methodCallExpression.Arguments[1])); } else { MethodCallTransformerUtility.CheckConstantExpression(methodCallExpression.Method.Name, methodCallExpression.Arguments[2], "language parameter"); var compositeExpression = new SqlCompositeCustomTextGeneratorExpression( typeof(string), new SqlCustomTextExpression("LANGUAGE ", typeof(string)), methodCallExpression.Arguments[2]); return(new SqlFunctionExpression( typeof(bool), "CONTAINS", methodCallExpression.Arguments[0], methodCallExpression.Arguments[1], compositeExpression)); } }
public Expression Transform(MethodCallExpression methodCallExpression) { ArgumentUtility.CheckNotNull("methodCallExpression", methodCallExpression); MethodCallTransformerUtility.CheckArgumentCount(methodCallExpression, 1, 2); MethodCallTransformerUtility.CheckInstanceMethod(methodCallExpression); var startIndexExpression = Expression.Add(methodCallExpression.Arguments[0], new SqlLiteralExpression(1)); if (methodCallExpression.Arguments.Count == 1) { return(new SqlFunctionExpression( methodCallExpression.Type, "STUFF", methodCallExpression.Object, startIndexExpression, new SqlLengthExpression(methodCallExpression.Object), new SqlLiteralExpression(""))); } else if (methodCallExpression.Arguments.Count == 2) { return(new SqlFunctionExpression( methodCallExpression.Type, "STUFF", methodCallExpression.Object, startIndexExpression, methodCallExpression.Arguments[1], new SqlLiteralExpression(""))); } else { var message = string.Format( "Remove function with {0} arguments is not supported. Expression: '{1}'", methodCallExpression.Arguments.Count, methodCallExpression); throw new NotSupportedException(message); } }
public Expression Transform(MethodCallExpression methodCallExpression) { ArgumentUtility.CheckNotNull("methodCallExpression", methodCallExpression); MethodCallTransformerUtility.CheckArgumentCount(methodCallExpression, 2); MethodCallTransformerUtility.CheckInstanceMethod(methodCallExpression); MethodCallTransformerUtility.CheckConstantExpression("Insert", methodCallExpression.Arguments[0], "insertionIndex"); var insertionIndexExpression = Expression.Add(methodCallExpression.Arguments[0], new SqlLiteralExpression(1)); var testExpression = Expression.Equal(new SqlLengthExpression(methodCallExpression.Object), insertionIndexExpression); var concatMethod = typeof(string).GetMethod("Concat", new[] { typeof(string), typeof(string) }); var thenExpression = Expression.Add(methodCallExpression.Object, methodCallExpression.Arguments[1], concatMethod); var elseExpression = new SqlFunctionExpression( methodCallExpression.Type, "STUFF", methodCallExpression.Object, insertionIndexExpression, new SqlLiteralExpression(0), methodCallExpression.Arguments[1]); return(Expression.Condition(testExpression, thenExpression, elseExpression)); }
public Expression Transform(MethodCallExpression methodCallExpression) { MethodCallTransformerUtility.CheckArgumentCount(methodCallExpression, 1, 2, 3); MethodCallTransformerUtility.CheckInstanceMethod(methodCallExpression); if (methodCallExpression.Arguments.Count == 1) { var lenExpression = new SqlLengthExpression(methodCallExpression.Arguments[0]); var testPredicate = Expression.Equal(lenExpression, new SqlLiteralExpression(0)); var charIndexExpression = new SqlFunctionExpression( methodCallExpression.Type, "CHARINDEX", methodCallExpression.Arguments[0], methodCallExpression.Object); var elseValue = Expression.Subtract(charIndexExpression, new SqlLiteralExpression(1)); return(Expression.Condition(testPredicate, new SqlLiteralExpression(0), elseValue)); } else if (methodCallExpression.Arguments.Count == 2) { var startIndexExpression = Expression.Add(methodCallExpression.Arguments[1], new SqlLiteralExpression(1)); var lenArgExpression = new SqlLengthExpression(methodCallExpression.Arguments[0]); var leftTestPredicate = Expression.Equal(lenArgExpression, new SqlLiteralExpression(0)); var lenObjectExpression = new SqlLengthExpression(methodCallExpression.Object); var rightTestpredicate = Expression.LessThanOrEqual(startIndexExpression, lenObjectExpression); var testPredicate = Expression.AndAlso(leftTestPredicate, rightTestpredicate); var charIndexExpression = new SqlFunctionExpression( methodCallExpression.Type, "CHARINDEX", methodCallExpression.Arguments[0], methodCallExpression.Object, startIndexExpression); var elseValue = Expression.Subtract(charIndexExpression, new SqlLiteralExpression(1)); return(Expression.Condition(testPredicate, methodCallExpression.Arguments[1], elseValue)); } else if (methodCallExpression.Arguments.Count == 3) { var startIndexExpression = Expression.Add(methodCallExpression.Arguments[1], new SqlLiteralExpression(1)); var lenArgExpression = new SqlLengthExpression(methodCallExpression.Arguments[0]); var leftTestPredicate = Expression.Equal(lenArgExpression, new SqlLiteralExpression(0)); var lenObjectExpression = new SqlLengthExpression(methodCallExpression.Object); var rightTestpredicate = Expression.LessThanOrEqual(startIndexExpression, lenObjectExpression); var testPredicate = Expression.AndAlso(leftTestPredicate, rightTestpredicate); var startAddCountExpression = Expression.Add(methodCallExpression.Arguments[1], methodCallExpression.Arguments[2]); var substringExpression = new SqlFunctionExpression( typeof(string), "SUBSTRING", methodCallExpression.Object, new SqlLiteralExpression(1), startAddCountExpression); var charIndexExpression = new SqlFunctionExpression( methodCallExpression.Type, "CHARINDEX", methodCallExpression.Arguments[0], substringExpression, startIndexExpression); var elseValue = Expression.Subtract(charIndexExpression, new SqlLiteralExpression(1)); return(Expression.Condition(testPredicate, methodCallExpression.Arguments[1], elseValue)); } else { var message = string.Format( "IndexOf function with {0} arguments is not supported. Expression: '{1}'", methodCallExpression.Arguments.Count, FormattingExpressionTreeVisitor.Format(methodCallExpression)); throw new NotSupportedException(message); } }