using System;
using System.Linq.Expressions;
using Telerik.Windows.Data;

namespace WpfApplication1
{
    public class PredicateFilterDescriptor<T> : FilterDescriptorBase
    {
        private Expression<Func<T, bool>> predicate;

        public Expression<Func<T, bool>> Predicate
        {
            get
            {
                return this.predicate;
            }
            set
            {
                if (this.predicate != value)
                {
                    this.predicate = value;
                    this.OnPropertyChanged("Predicate");
                }
            }
        }

        protected override Expression CreateFilterExpression(ParameterExpression parameterExpression)
        {
            return PredicateRewriter.Rewrite(this.Predicate, parameterExpression);
        }
    }
}