Skip to content

Commit d73c916

Browse files
committed
Fix .NET 10 enum array Contains expression tree handling
.NET 10 may compile array.Contains() as a static method with 3 arguments (source, item, comparer) instead of 2. Handle all forms: instance with 1+ args, static with 2+ args. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 5e097ca commit d73c916

2 files changed

Lines changed: 18 additions & 22 deletions

File tree

src/NzbDrone.Core/Datastore/WhereBuilderPostgres.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -285,27 +285,25 @@ private void ParseContainsExpression(MethodCallExpression expression)
285285
private void ParseEnumerableContains(MethodCallExpression body)
286286
{
287287
// Fish out the list and the item to compare
288-
// It's in a different form for arrays and Lists
288+
// It's in a different form for arrays, Lists, and different .NET versions
289289
var list = body.Object;
290290
Expression item;
291291

292-
if (list != null)
292+
if (list != null && body.Arguments.Count >= 1)
293293
{
294-
// Generic collection
294+
// Instance method: list.Contains(item) or list.Contains(item, comparer)
295295
item = body.Arguments[0];
296296
}
297-
else
297+
else if (body.Arguments.Count >= 2)
298298
{
299-
// Static method
300-
// Must be Enumerable.Contains(source, item) or Array static Contains
301-
if (body.Arguments.Count != 2)
302-
{
303-
throw new NotSupportedException("Unexpected form of Enumerable.Contains");
304-
}
305-
299+
// Static method: Enumerable.Contains(source, item) or similar
306300
list = body.Arguments[0];
307301
item = body.Arguments[1];
308302
}
303+
else
304+
{
305+
throw new NotSupportedException("Unexpected form of Contains expression");
306+
}
309307

310308
_sb.Append('(');
311309

src/NzbDrone.Core/Datastore/WhereBuilderSqlite.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -285,27 +285,25 @@ private void ParseContainsExpression(MethodCallExpression expression)
285285
private void ParseEnumerableContains(MethodCallExpression body)
286286
{
287287
// Fish out the list and the item to compare
288-
// It's in a different form for arrays and Lists
288+
// It's in a different form for arrays, Lists, and different .NET versions
289289
var list = body.Object;
290290
Expression item;
291291

292-
if (list != null)
292+
if (list != null && body.Arguments.Count >= 1)
293293
{
294-
// Generic collection
294+
// Instance method: list.Contains(item) or list.Contains(item, comparer)
295295
item = body.Arguments[0];
296296
}
297-
else
297+
else if (body.Arguments.Count >= 2)
298298
{
299-
// Static method
300-
// Must be Enumerable.Contains(source, item) or Array static Contains
301-
if (body.Arguments.Count != 2)
302-
{
303-
throw new NotSupportedException("Unexpected form of Enumerable.Contains");
304-
}
305-
299+
// Static method: Enumerable.Contains(source, item) or similar
306300
list = body.Arguments[0];
307301
item = body.Arguments[1];
308302
}
303+
else
304+
{
305+
throw new NotSupportedException("Unexpected form of Contains expression");
306+
}
309307

310308
_sb.Append('(');
311309

0 commit comments

Comments
 (0)