SpecificationExtensions.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using JetBrains.Annotations;
  2. namespace Abp.Specifications
  3. {
  4. public static class SpecificationExtensions
  5. {
  6. /// <summary>
  7. /// Combines the current specification instance with another specification instance
  8. /// and returns the combined specification which represents that both the current and
  9. /// the given specification must be satisfied by the given object.
  10. /// </summary>
  11. /// <param name="specification">The specification</param>
  12. /// <param name="other">The specification instance with which the current specification is combined.</param>
  13. /// <returns>The combined specification instance.</returns>
  14. public static ISpecification<T> And<T>([NotNull] this ISpecification<T> specification, [NotNull] ISpecification<T> other)
  15. {
  16. Check.NotNull(specification, nameof(specification));
  17. Check.NotNull(other, nameof(other));
  18. return new AndSpecification<T>(specification, other);
  19. }
  20. /// <summary>
  21. /// Combines the current specification instance with another specification instance
  22. /// and returns the combined specification which represents that either the current or
  23. /// the given specification should be satisfied by the given object.
  24. /// </summary>
  25. /// <param name="specification">The specification</param>
  26. /// <param name="other">The specification instance with which the current specification
  27. /// is combined.</param>
  28. /// <returns>The combined specification instance.</returns>
  29. public static ISpecification<T> Or<T>([NotNull] this ISpecification<T> specification, [NotNull] ISpecification<T> other)
  30. {
  31. Check.NotNull(specification, nameof(specification));
  32. Check.NotNull(other, nameof(other));
  33. return new OrSpecification<T>(specification, other);
  34. }
  35. /// <summary>
  36. /// Combines the current specification instance with another specification instance
  37. /// and returns the combined specification which represents that the current specification
  38. /// should be satisfied by the given object but the specified specification should not.
  39. /// </summary>
  40. /// <param name="specification">The specification</param>
  41. /// <param name="other">The specification instance with which the current specification
  42. /// is combined.</param>
  43. /// <returns>The combined specification instance.</returns>
  44. public static ISpecification<T> AndNot<T>([NotNull] this ISpecification<T> specification, [NotNull] ISpecification<T> other)
  45. {
  46. Check.NotNull(specification, nameof(specification));
  47. Check.NotNull(other, nameof(other));
  48. return new AndNotSpecification<T>(specification, other);
  49. }
  50. /// <summary>
  51. /// Reverses the current specification instance and returns a specification which represents
  52. /// the semantics opposite to the current specification.
  53. /// </summary>
  54. /// <returns>The reversed specification instance.</returns>
  55. public static ISpecification<T> Not<T>([NotNull] this ISpecification<T> specification)
  56. {
  57. Check.NotNull(specification, nameof(specification));
  58. return new NotSpecification<T>(specification);
  59. }
  60. }
  61. }