Resharper with predicates

Posts   
 
    
caffreys
User
Posts: 65
Joined: 25-Jan-2009
# Posted on: 24-Dec-2013 01:55:38   

I thought I was going crazy but Resharper insists that the following expression is always false:


    bucket.PredicateExpression.Add(
        MyTableFields.MyBool == true);

It recommends:


    bucket.PredicateExpression.Add(false);

...which is dumb.

After some pointless refactoring my original code (and the predicate) is correct. Resharper has got this wrong. Bit annoying though as I put a lot of faith in Resharper and in most cases it seems to know better than I do.

Would be nice to find something which satisfies Resharper as i'm adding a lot of filtering code to my RESTful services and each time I add a bool predicate I get this warning.

Walaa avatar
Walaa
Support Team
Posts: 14994
Joined: 21-Aug-2005
# Posted on: 24-Dec-2013 05:46:14   

We have many users using Resharper, and this is the first time we get this issue.

But anyway, I guess you need to talk to Resharper about this. The predicate is perfectly fine.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39888
Joined: 17-Aug-2003
# Posted on: 24-Dec-2013 09:38:09   

I think it's because we overload the operator '==', and resharper can't know that. This means that it looks at the code as if it's normal C# and in that light it's always false, however the operator we overloaded creates a predicate.

So for predicated you can safely ignore the warnings. If you don't want to ignore the warnings, please use the queryspec extension methods to create the predicate differently:

bucket.PredicateExpression.Add(MyTableFields.MyBool.Equal(true));

Frans Bouma | Lead developer LLBLGen Pro