2011-01-16 2 views
2

Es domänenspezifische Klasse:Wie bekomme ich nicht Ausdrucksprädikat von Ausdruck Prädikat?

public class Account : IEntity 
{ 
    public bool IsActive { get; set; } 
    public DateTime ExpirationDate { get; set; } 
} 

und einige Prädikate für Konten von Datenquelle zu holen:

Expression<Func<Account, bool>> predicate = a => a.IsActive == false && a.ExpirationDate < DateTime.Now; 

List<Account> lst = new List<Account>(); 
lst.AsQueryable().Where(predicate); 

Wie kann ich not_predicate von meinem Prädikat erzeugen? Wo not_predicate ist:

!(a.IsActive == false && a.ExpirationDate < DateTime.Now) 

Antwort

2

Dies könnte slights zwickt müssen (ich bin nicht an einem PC) - aber so etwas wie:

var not = Expression.Lambda<Func<Account,bool>>(
    Expression.Not(predicate.Body), predicate.Parameters); 
Verwandte Themen