11namespace DotNetToolkit . Repository . Queries . Strategies
22{
3+ using JetBrains . Annotations ;
34 using System ;
45 using System . Linq ;
56 using System . Linq . Expressions ;
@@ -16,9 +17,9 @@ public class SpecificationQueryStrategy<T> : ISpecificationQueryStrategy<T>
1617 /// Initializes a new instance of the <see cref="SpecificationQueryStrategy{T}" /> class.
1718 /// </summary>
1819 /// <param name="predicate">A function to test the entity and determine if it satisfies the specified criteria.</param>
19- public SpecificationQueryStrategy ( Expression < Func < T , bool > > predicate )
20+ public SpecificationQueryStrategy ( [ NotNull ] Expression < Func < T , bool > > predicate )
2021 {
21- Predicate = predicate ;
22+ Predicate = Guard . NotNull ( predicate , nameof ( predicate ) ) ;
2223 }
2324
2425 #endregion
@@ -28,33 +29,33 @@ public SpecificationQueryStrategy(Expression<Func<T, bool>> predicate)
2829 /// <summary>
2930 /// Returns a new specificationStrategy which has been combined with the current and the specified specificationStrategy using the logical "and".
3031 /// </summary>
31- public ISpecificationQueryStrategy < T > And ( SpecificationQueryStrategy < T > specificationStrategy )
32+ public ISpecificationQueryStrategy < T > And ( [ NotNull ] SpecificationQueryStrategy < T > specificationStrategy )
3233 {
33- return new SpecificationQueryStrategy < T > ( Predicate . And ( specificationStrategy . Predicate ) ) ;
34+ return new SpecificationQueryStrategy < T > ( Predicate . And ( Guard . NotNull ( specificationStrategy , nameof ( specificationStrategy ) ) . Predicate ) ) ;
3435 }
3536
3637 /// <summary>
3738 /// Returns a new specificationStrategy which has been combined with the current specified predicate using the logical "and".
3839 /// </summary>
39- public ISpecificationQueryStrategy < T > And ( Expression < Func < T , bool > > predicate )
40+ public ISpecificationQueryStrategy < T > And ( [ NotNull ] Expression < Func < T , bool > > predicate )
4041 {
41- return new SpecificationQueryStrategy < T > ( Predicate . And ( predicate ) ) ;
42+ return new SpecificationQueryStrategy < T > ( Predicate . And ( Guard . NotNull ( predicate , nameof ( predicate ) ) ) ) ;
4243 }
4344
4445 /// <summary>
4546 /// Returns a new specificationStrategy which has been combined with the current and the specified specificationStrategy using the logical "or".
4647 /// </summary>
47- public ISpecificationQueryStrategy < T > Or ( SpecificationQueryStrategy < T > specificationStrategy )
48+ public ISpecificationQueryStrategy < T > Or ( [ NotNull ] SpecificationQueryStrategy < T > specificationStrategy )
4849 {
49- return new SpecificationQueryStrategy < T > ( Predicate . Or ( specificationStrategy . Predicate ) ) ;
50+ return new SpecificationQueryStrategy < T > ( Predicate . Or ( Guard . NotNull ( specificationStrategy , nameof ( specificationStrategy ) ) . Predicate ) ) ;
5051 }
5152
5253 /// <summary>
5354 /// Returns a new specificationStrategy which has been combined with the current specified predicate using the logical "or".
5455 /// </summary>
55- public ISpecificationQueryStrategy < T > Or ( Expression < Func < T , bool > > predicate )
56+ public ISpecificationQueryStrategy < T > Or ( [ NotNull ] Expression < Func < T , bool > > predicate )
5657 {
57- return new SpecificationQueryStrategy < T > ( Predicate . Or ( predicate ) ) ;
58+ return new SpecificationQueryStrategy < T > ( Predicate . Or ( Guard . NotNull ( predicate , nameof ( predicate ) ) ) ) ;
5859 }
5960
6061 /// <summary>
@@ -79,19 +80,21 @@ public ISpecificationQueryStrategy<T> Not()
7980 /// </summary>
8081 /// <param name="query">The entity query.</param>
8182 /// <returns>The collection of entities that satisfied the criteria specified by the <see cref="ISpecificationQueryStrategy{T}.Predicate" /> from the query.</returns>
82- public virtual IQueryable < T > SatisfyingEntitiesFrom ( IQueryable < T > query )
83+ public virtual IQueryable < T > SatisfyingEntitiesFrom ( [ NotNull ] IQueryable < T > query )
8384 {
84- return Predicate == null ? query : query . Where ( Predicate ) ;
85+ return Guard . NotNull ( query , nameof ( query ) ) . Where ( Predicate ) ;
8586 }
8687
8788 /// <summary>
8889 /// Determines wheter the entity that satisfied the criteria specified by the <see cref="ISpecificationQueryStrategy{T}.Predicate" />.
8990 /// </summary>
9091 /// <param name="entity">The entity to test.</param>
9192 /// <returns><c>true</c> if the entity satisfied the criteria specified by the <see cref="ISpecificationQueryStrategy{T}.Predicate" />; otherwise, <c>false</c>.</returns>
92- public bool IsSatisfiedBy ( T entity )
93+ public bool IsSatisfiedBy ( [ NotNull ] T entity )
9394 {
94- return Predicate == null || new [ ] { entity } . AsQueryable ( ) . Any ( Predicate ) ;
95+ return new [ ] { Guard . NotNull ( entity , nameof ( entity ) ) }
96+ . AsQueryable ( )
97+ . Any ( Predicate ) ;
9598 }
9699
97100 #endregion
0 commit comments