Created
October 26, 2009 16:17
-
-
Save panesofglass/218767 to your computer and use it in GitHub Desktop.
A factory for creating specifications inline using Expressions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Linq.Expressions; | |
| namespace Foundation.Specifications | |
| { | |
| /// <summary> | |
| /// Defines a factory for creating specifications inline. | |
| /// </summary> | |
| public static class SpecificationFactory | |
| { | |
| #region methods | |
| /// <summary> | |
| /// Factory method to creates an <see cref="InlineSpecification{T}" /> specifaction using the | |
| /// specified <paramref name="expression"/>. | |
| /// </summary> | |
| /// <typeparam name="T">The type of the entity used by the specification.</typeparam> | |
| /// <param name="expression">The expression.</param> | |
| /// <returns>The <see cref="Specification{T}" />.</returns> | |
| public static ISpecification<T> Create<T>(Expression<Func<T, bool>> expression) | |
| { | |
| return new InlineSpecification<T>(expression); | |
| } | |
| #endregion | |
| #region nested type: InlineSpecification | |
| /// <summary> | |
| /// Defines an internal implemenation for creating inline specifications. | |
| /// </summary> | |
| /// <typeparam name="T"></typeparam> | |
| internal class InlineSpecification<T> : Specification<T> | |
| { | |
| private readonly Expression<Func<T, bool>> _condition; | |
| /// <summary> | |
| /// Gets the condition. | |
| /// </summary> | |
| /// <value>The condition.</value> | |
| public override Expression<Func<T, bool>> Condition | |
| { | |
| get { return _condition; } | |
| } | |
| /// <summary> | |
| /// Initializes a new instance of the <see cref="InlineSpecification<T>"/> class. | |
| /// </summary> | |
| /// <param name="condition">The condition.</param> | |
| public InlineSpecification(Expression<Func<T, bool>> condition) | |
| { | |
| _condition = condition; | |
| } | |
| } | |
| #endregion | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment