63 lines
3.1 KiB
C#
Raw Normal View History

2025-04-24 18:31:27 +08:00

using System;
using System.Linq.Expressions;
namespace MyCode.Project.Infrastructure
{
/// <summary>
/// Represents that the implemented classes are specifications. For more
/// information about the specification pattern, please refer to
/// http://martinfowler.com/apsupp/spec.pdf.
/// </summary>
/// <typeparam name="T">The type of the object to which the specification
/// is applied.</typeparam>
public interface ISpecification<T>
{
/// <summary>
/// Returns a <see cref="System.Boolean"/> value which indicates whether the specification
/// is satisfied by the given object.
/// </summary>
/// <param name="obj">The object to which the specification is applied.</param>
/// <returns>True if the specification is satisfied, otherwise false.</returns>
bool IsSatisfiedBy(T obj);
/// <summary>
/// Combines the current specification instance with another specification instance
/// and returns the combined specification which represents that both the current and
/// the given specification must be satisfied by the given object.
/// </summary>
/// <param name="other">The specification instance with which the current specification
/// is combined.</param>
/// <returns>The combined specification instance.</returns>
ISpecification<T> And(ISpecification<T> other);
/// <summary>
/// Combines the current specification instance with another specification instance
/// and returns the combined specification which represents that either the current or
/// the given specification should be satisfied by the given object.
/// </summary>
/// <param name="other">The specification instance with which the current specification
/// is combined.</param>
/// <returns>The combined specification instance.</returns>
ISpecification<T> Or(ISpecification<T> other);
/// <summary>
/// Combines the current specification instance with another specification instance
/// and returns the combined specification which represents that the current specification
/// should be satisfied by the given object but the specified specification should not.
/// </summary>
/// <param name="other">The specification instance with which the current specification
/// is combined.</param>
/// <returns>The combined specification instance.</returns>
ISpecification<T> AndNot(ISpecification<T> other);
/// <summary>
/// Reverses the current specification instance and returns a specification which represents
/// the semantics opposite to the current specification.
/// </summary>
/// <returns>The reversed specification instance.</returns>
ISpecification<T> Not();
/// <summary>
/// Gets the LINQ expression which represents the current specification.
/// </summary>
/// <returns>The LINQ expression.</returns>
Expression<Func<T, bool>> GetExpression();
}
}