using System;
using System.Linq.Expressions;
namespace MyCode.Project.Infrastructure
{
///
/// 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
{
#region Ctor
///
/// Constructs a new instance of AndNotSpecification<T> class.
///
/// The first specification.
/// The second specification.
public AndNotSpecification(ISpecification left, ISpecification right) : base(left, right) { }
#endregion
#region Public Methods
///
/// Gets the LINQ expression which represents the current specification.
///
/// The LINQ expression.
public override Expression> GetExpression()
{
var bodyNot = Expression.Not(Right.GetExpression().Body);
var bodyNotExpression = Expression.Lambda>(bodyNot, Right.GetExpression().Parameters);
return Left.GetExpression().And(bodyNotExpression);
}
#endregion
}
}