Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 122079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T04:04:19+00:00 2026-05-11T04:04:19+00:00

Today we faced a quite simple problem that were made even simpler by the

  • 0

Today we faced a quite simple problem that were made even simpler by the dear predicates. We had a kind of event log and wanted to filter it client side (Windows Forms) using a list of criterias. We began by implementing to filter by a number of categories.

private List<Events> FilterEventsByCategory(List<Events> events,                                         List<Category> categories)  {   return events.FindAll(ev =>        categories.Exists(category => category.CategoryId==ev.CategoryId));  } 

The next step is to implement a couple of other filters. Do you know of a nice way to generalize these to maybe somehow not having to write one method per filter? Or at least a clean way to have a dynamic list of filters that we want to apply simultaneously.

The clients are still on framework 3.0 so no LINQ.

Update: I had a hard time deciding who I should give credit for my solution. Marc had some nice ideas and is really good at explaining them. Most probaly I would have got my answer from him if I only had explained my problem a little better. Ultimately it was the generic Filter class that cmartin provided that got me on track. The Filter class used below can be found in cmartins’ answer and the User class you get to dream up yourself.

var categoryFilter = new Filter<Event>(ev => categories.Exists(category => category.CategoryId == ev.CategoryId)); var userFilter = new Filter<Event>(ev => users.Exists(user => user.UserId == ev.UserId));  var filters = new List<Filter<Event>>(); filters.Add(categoryFilter); filters.Add(userFilter);  var eventsFilteredByAny = events.FindAll(ev => filters.Any(filter => filter.IsSatisfied(ev))); var eventsFilteredByAll = events.FindAll(ev => filters.All(filter => filter.IsSatisfied(ev))); 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T04:04:20+00:00Added an answer on May 11, 2026 at 4:04 am

    Here’s a very rudimentary sample of where I would start.

    internal class Program {     private static void Main()     {         var ms = new Category(1, 'Microsoft');         var sun = new Category(2, 'Sun');          var events = new List<Event>                          {                              new Event(ms, 'msdn event'),                              new Event(ms, 'mix'),                              new Event(sun, 'java event')                          };          var microsoftFilter = new Filter<Event>(e => e.CategoryId == ms.CategoryId);          var microsoftEvents = FilterEvents(events, microsoftFilter);          Console.Out.WriteLine(microsoftEvents.Count);     }      public static List<Event> FilterEvents(List<Event> events, Filter<Event> filter)     {         return events.FindAll(e => filter.IsSatisfied(e));     } }  public class Filter<T> where T: class {     private readonly Predicate<T> criteria;      public Filter(Predicate<T> criteria)     {         this.criteria = criteria;     }      public bool IsSatisfied(T obj)     {         return criteria(obj);     } }  public class Event {     public Event(Category category, string name)     {         CategoryId = category.CategoryId;         Name = name;     }      public int CategoryId { get; set; }     public string Name { get; set; } }  public class Category {     public Category(int categoryId, string name)     {         CategoryId = categoryId;         Name = name;     }      public string Name { get; set; }     public int CategoryId { get; set; } } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 239k
  • Answers 239k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer you can make it to template field and change value… May 13, 2026 at 7:01 am
  • Editorial Team
    Editorial Team added an answer It is not possible to change color of index's rows.… May 13, 2026 at 7:01 am
  • Editorial Team
    Editorial Team added an answer BillingInfo looks to me not like a component but an… May 13, 2026 at 7:01 am

Related Questions

Reading about the G.729 codec , I found this interesting tidbit about Comfort Noise
We all know MOSS is a royal pain in the gut. Today I am
Today I faced an interesting issue. I've been having an inheritance hierarchy with Hibernate
I'd like to hear some opinions or discussion on a matter of database design.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.