ExpressionSpecification.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. using System;
  2. using System.Linq.Expressions;
  3. namespace Abp.Specifications
  4. {
  5. /// <summary>
  6. /// Represents the specification which is represented by the corresponding
  7. /// LINQ expression.
  8. /// </summary>
  9. /// <typeparam name="T">The type of the object to which the specification is applied.</typeparam>
  10. public class ExpressionSpecification<T> : Specification<T>
  11. {
  12. private readonly Expression<Func<T, bool>> _expression;
  13. /// <summary>
  14. /// Initializes a new instance of <c>ExpressionSpecification&lt;T&gt;</c> class.
  15. /// </summary>
  16. /// <param name="expression">The LINQ expression which represents the current
  17. /// specification.</param>
  18. public ExpressionSpecification(Expression<Func<T, bool>> expression)
  19. {
  20. _expression = expression;
  21. }
  22. /// <summary>
  23. /// Gets the LINQ expression which represents the current specification.
  24. /// </summary>
  25. /// <returns>The LINQ expression.</returns>
  26. public override Expression<Func<T, bool>> ToExpression()
  27. {
  28. return _expression;
  29. }
  30. }
  31. }