The following pattern:
values.All(e => document.A.Contains(e)) // where values is a constant array
is translated to the filter:
{ A : { $all : [<values>] } }
This is true of both LINQ2 and LINQ3.
However, LINQ3 currently only supports this pattern if the Contains method resolves to Enumerable.Contains. We need to support other Contains methods, for example ICollection.Contains.
Instead of looking for specific Contains methods (there are many), we can see if the Contains method "looks" like a Contains method:
- Is named "Contains"
- Return type is bool
- Has two parameters (call them source and value)
- Source implements IEnumerable<TItem>
- value is assignable to TItem
The Contains method could be either a static or an instance method:
- if static, source is the first argument and value is the second
- if instance, source is the object itself and value is the only argument