While I am thinking about it, Kar-khan wrote the following extension for LinqSpecs:
using LinqSpecs;
namespace AMD.Avalanche.Core.Utils
{
public class SpecificationBuilder<T>
{
private Specification<T> _spec;
public SpecificationBuilder() { }
public void AddAnd(Specification<T> specification)
{
if (_spec == null)
_spec = specification;
else
_spec = new AndSpecification<T>(_spec, specification);
}
public void AddOr(Specification<T> specification)
{
if (_spec == null)
_spec = specification;
else
_spec = new OrSpecification<T>(_spec, specification);
}
public Specification<T> ToSpecification()
{
return _spec;
}
}
}
Use it like so...
var specBuilder = new SpecificationBuilderlt;Foogt;();
specBuilder.AddAnd(MySpecs.NameCriteria(whatever));
No comments:
Post a Comment