using System;
using System.Linq.Expressions;
namespace Abp.Specifications
{
///
/// Represents the combined specification which indicates that the first specification
/// can be satisifed by the given object whereas the second one cannot.
///
/// The type of the object to which the specification is applied.
public class AndNotSpecification : CompositeSpecification
{
///
/// Constructs a new instance of class.
///
/// The first specification.
/// The second specification.
public AndNotSpecification(ISpecification left, ISpecification right) : base(left, right) { }
///
/// Gets the LINQ expression which represents the current specification.
///
/// The LINQ expression.
public override Expression> ToExpression()
{
var rightExpression = Right.ToExpression();
var bodyNot = Expression.Not(rightExpression.Body);
var bodyNotExpression = Expression.Lambda>(bodyNot, rightExpression.Parameters);
return Left.ToExpression().And(bodyNotExpression);
}
}
}