File tree Expand file tree Collapse file tree
src/NzbDrone.Core/Datastore Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments