/// <summary> /// Creates and return a filter associated with the specified key added for the context. /// </summary> /// <typeparam name="T">The type of elements of the query.</typeparam> /// <param name="key">The filter key associated to the filter.</param> /// <param name="queryFilter">The query filter to apply to the context.</param> /// <param name="isEnabled">true if the filter is enabled.</param> /// <returns>The filter created and added to the context.</returns> public static BaseQueryFilterInterceptor Filter <T>(object key, Func <IQueryable <T>, IQueryable <T> > queryFilter, bool isEnabled = true) where T : class { BaseQueryFilterInterceptor filter; // FilterByKey { if (!GlobalFiltersByKey.TryGetValue(key, out filter)) { filter = new QueryFilterInterceptor <T>(queryFilter) { IsDefaultEnabled = isEnabled }; GlobalFiltersByKey.AddOrUpdate(key, filter, (o, interceptorFilter) => filter); } } // FilterByType { if (!GlobalFilterByType.ContainsKey(typeof(T))) { GlobalFilterByType.AddOrUpdate(typeof(T), new List <BaseQueryFilterInterceptor>(), (type, list) => list); } GlobalFilterByType[typeof(T)].Add(filter); } ClearAllCache(); return(filter); }
/// <summary>Gets the filter associated with the specified key from the context.</summary> /// <param name="key">The filter key associated to the filter.</param> /// <returns>The filter associated with the specified key from the context.</returns> public static BaseQueryFilterInterceptor Filter(object key) { BaseQueryFilterInterceptor filter; GlobalFiltersByKey.TryGetValue(key, out filter); return(filter); }