37 lines
1.4 KiB
C#
37 lines
1.4 KiB
C#
using System;
|
|
using System.Linq.Expressions;
|
|
|
|
namespace MyCode.Project.Infrastructure
|
|
{
|
|
/// <summary>
|
|
/// Represents the combined specification which indicates that both of the given
|
|
/// specifications should be satisfied by the given object.
|
|
/// </summary>
|
|
/// <typeparam name="T">The type of the object to which the specification is applied.</typeparam>
|
|
public class AndSpecification<T> : CompositeSpecification<T>
|
|
{
|
|
#region Ctor
|
|
/// <summary>
|
|
/// Constructs a new instance of <c>AndSpecification<T></c> class.
|
|
/// </summary>
|
|
/// <param name="left">The first specification.</param>
|
|
/// <param name="right">The second specification.</param>
|
|
public AndSpecification(ISpecification<T> left, ISpecification<T> right) : base(left, right) { }
|
|
#endregion
|
|
|
|
#region Public Methods
|
|
/// <summary>
|
|
/// Gets the LINQ expression which represents the current specification.
|
|
/// </summary>
|
|
/// <returns>The LINQ expression.</returns>
|
|
public override Expression<Func<T, bool>> GetExpression()
|
|
{
|
|
//var body = Expression.AndAlso(Left.GetExpression().Body, Right.GetExpression().Body);
|
|
//return Expression.Lambda<Func<T, bool>>(body, Left.GetExpression().Parameters);
|
|
return Left.GetExpression().And(Right.GetExpression());
|
|
}
|
|
#endregion
|
|
}
|
|
|
|
}
|