// public static methods public static AstFilter Translate(TranslationContext context, MethodCallExpression expression) { var method = expression.Method; var arguments = expression.Arguments; if (method.IsOneOf(__stringInOrNinMethods)) { var fieldExpression = arguments[0]; var field = ExpressionToFilterFieldTranslator.Translate(context, fieldExpression); var valuesExpression = arguments[1]; if (valuesExpression is ConstantExpression constantValuesExpression) { var serializedValues = new List <BsonValue>(); var values = ((IEnumerable <StringOrRegularExpression>)constantValuesExpression.Value).ToList(); var stringSerializer = StringSerializer.Instance; var regularExpressionSerializer = BsonRegularExpressionSerializer.Instance; foreach (var value in values) { BsonValue serializedValue; if (value?.Type == typeof(BsonRegularExpression)) { var regularExpression = value.RegularExpression; serializedValue = SerializationHelper.SerializeValue(regularExpressionSerializer, regularExpression); } else { var @string = value?.String; serializedValue = SerializationHelper.SerializeValue(stringSerializer, @string); } serializedValues.Add(serializedValue); } return(method.IsOneOf(__stringInMethods) ? AstFilter.In(field, serializedValues) : AstFilter.Nin(field, serializedValues)); } } throw new ExpressionNotSupportedException(expression); }