I've found that the IsStarted
property seems to show if a predicate has been assigned.
In my code I've used that to build up composite search statements where the search parameters are optional. E.g.
var quoteDatePredicate= PredicateBuilder.New<SearchData>();
if (searchCriteria.QuoteFromDate.HasValue)
{
quoteDatePredicate.And(x => x.QuoteDate >= searchCriteria.QuoteFromDate);
}
var saleDatePredicate = PredicateBuilder.New<SearchData>();
if (searchCriteria.SaleDate.HasValue)
{
saleDatePredicate.And(x => x.SaleDate >= searchCriteria.SaleDateFrom);
}
And then I create another predicate variable and use an If
statement to add any predicates that were actually assigned to:
var datesPredicate = PredicateBuilder.New<SearchData>();
if (quoteDatePredicate.IsStarted) datesPredicate.Or(quoteDatePredicate);
if (saleDatePredicate.IsStarted) datesPredicate.Or(saleDatePredicate);
So far that seems to work fine in my code.
Alternatively, comparing an assigned and unassigned predicate variable in the debugger seems to suggest you could use this to check if a predicate has been assigned:
if (dueOutOfDatePredicate.Parameters[0].Name = "f")
I haven't tried that though.