Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not(). Possibility to negate the whole predicate. #136

Merged
merged 2 commits into from
Feb 6, 2021
Merged

Not(). Possibility to negate the whole predicate. #136

merged 2 commits into from
Feb 6, 2021

Conversation

LucasDiogoDeon
Copy link
Contributor

@LucasDiogoDeon LucasDiogoDeon commented Jan 29, 2021

Usage:

var predicate = PredicateBuilder.New<Product>(true);
predicate = predicate.And(x => x.Discontinued) // Discontinued == true
predicate = predicate.And(x => x.Id > 10) // Discontinued == true && Id > 10
predicate = predicate.Not(); // !(Discontinued == true && Id > 10)

I am currently using an implementation that uses Reflection, but this way is better.

Usage:
var predicate = PredicateBuilder.New<Product>(true);
predicate = predicate.And(x => x.Discontinued) // Discontinued == true
predicate = predicate.And(x => x.Id > 10) // Discontinued == true && Id > 10
predicate = predicate.Not(); // !(Discontinued == true && Id > 10)

I am currently using an implementation that uses Reflection, but this way is better.
/// <summary>Not</summary>
public Expression<Func<T, bool>> Not()
{
if (IsStarted)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please use { and } for if-statements?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.

@StefH
Copy link
Collaborator

StefH commented Feb 2, 2021

I'll merge and create a new version this weekend.

@StefH StefH merged commit cac8b4e into scottksmith95:master Feb 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants