Ejemplo n.º 1
0
        public void ClearFilter()
        {
            FilterParams = null;
            SearchString = string.Empty;

            Criteria = DetachedCriteria.For <EntityBase>();
        }
Ejemplo n.º 2
0
    public static IEnumerable <T> Filter <T>(this IEnumerable <T> source, IFilterParams <T> filterParams)
    {
        var sourceProps = typeof(T).GetProperties();
        var filterProps = filterParams.GetType().GetProperties();

        foreach (var prop in filterProps)
        {
            var filterAttr = prop.GetCustomAttribute <FilterAttribute>();
            if (filterAttr == null)
            {
                continue;
            }
            object val = prop.GetValue(filterParams);
            if (val == null)
            {
                continue;
            }
            // oops.. little hole..
            if (prop.PropertyType == typeof(string) && (string)val == string.Empty)
            {
                continue;
            }
            string propName = string.IsNullOrEmpty(filterAttr.PropName)
                                        ? prop.Name
                                        : filterAttr.PropName;
            if (!sourceProps.Any(x => x.Name == propName))
            {
                continue;
            }
            Func <T, bool> filter = CreateFilter <T>(propName, filterAttr.FilterType, val);
            source = source.Where(filter);
        }
        return(source);
    }
Ejemplo n.º 3
0
 public void ClearFilterParams()
 {
     FilterParams = null;
 }