Skip to content

Instantly share code, notes, and snippets.

@thdotnet
Created November 23, 2021 21:58
Show Gist options
  • Save thdotnet/9898843591b1f7633b25ebf0fb948671 to your computer and use it in GitHub Desktop.
Save thdotnet/9898843591b1f7633b25ebf0fb948671 to your computer and use it in GitHub Desktop.
Generic Specification
using System;
using System.Linq.Expressions;
namespace Sample
{
public class GenericSpecification<T>
{
public Expression<Func<T, bool>> Expression { get; }
public GenericSpecification(Expression<T, bool> expression)
{
Expression = expression;
}
public bool IsSatisfiedBy(T entity)
{
return Expression.Compile().Invoke(entity);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment