// public static methods public static AstFilter Translate(TranslationContext context, MethodCallExpression expression) { if (StringExpressionToRegexFilterTranslator.CanTranslate(expression)) { return(StringExpressionToRegexFilterTranslator.Translate(context, expression)); } throw new ExpressionNotSupportedException(expression); }
public static AstFilter Translate(TranslationContext context, MethodCallExpression expression) { if (StringExpressionToRegexFilterTranslator.CanTranslate(expression)) { return(StringExpressionToRegexFilterTranslator.Translate(context, expression)); } var method = expression.Method; var arguments = expression.Arguments; if (method.IsStatic && method.Name == "Contains" && method.ReturnType == typeof(bool) && arguments.Count == 2) { var sourceExpression = arguments[0]; var sourceType = sourceExpression.Type; var itemExpression = arguments[1]; var itemType = itemExpression.Type; if (TypeImplementsIEnumerable(sourceType, itemType)) { return(Translate(context, expression, sourceExpression, itemExpression)); } } if (!method.IsStatic && method.Name == "Contains" && method.ReturnType == typeof(bool) && arguments.Count == 1) { var sourceExpression = expression.Object; var sourceType = sourceExpression.Type; var itemExpression = arguments[0]; var itemType = itemExpression.Type; if (TypeImplementsIEnumerable(sourceType, itemType)) { return(Translate(context, expression, sourceExpression, itemExpression)); } } throw new ExpressionNotSupportedException(expression); }