We encountered a very simple problem today, which was simplified even with dear predictions. We had a type of event log and wanted to filter the client side (Windows form) by using a list of criteria we applied to filter by several categories.
Private list & lt; Events & gt; FilterEventsByCategory (List & Events; Events & gt; Events, Listings & lt; Categories & gt; Categories) {Return Events. FindAll (ev = & gt; categories.Exists (category = & gt; Category categoryId == ev.CategoryId)); }
The next step is to implement two other filters. Do you know a good way to normalize them, perhaps by writing in the form of one method per filter? Or at least one is a dynamic list of filters that we want to apply together.
Customers still have a framework of 3.0, so no LINQ.
Update: I had to decide which loan I should give to my solution. Mark had some good ideas and was really good to explain to them. Most likely that if I had explained my problem a bit better then I would get the answers. Eventually this was a generic filter class that provided CMTIN which I found on the track. The filter class below can be found in the reply to CMMTNET, and the user class can dream you yourself.
var categoryFilter = new filter & lt; Event & gt; (Ev = & gt; categories.Exists Category = & gt; Category; Category Id == ev.CategoryId)); Var userFilter = new filter & lt; Event & gt; (Ev = & gt; User example (user = & gt; user.uusid == ev.UserId)); Var filter = new list & lt; Filter & lt; Event & gt; & Gt; (); Filters.Add (categoryFilter); Filters.Add (userFilter); Var Event Filter Filter by ANY = Events.Fund L (EV => Filters. Any (Filters => Filters; IT Satisfied (EV)); Var Event Filter By Left ALL = events.FindAll (ev = & gt; Filters All (Filters = & gt; Filters. Dissatisfied (EV));
This is an initial sample where I will start
Internal class program {Private Static Zero Main () {var MS = New Category (1, "Microsoft"); Var Sun = New Category (2, "Sun"); Var Event = New List & lt; Event & gt; {New Event (MS, "MSDN Event"), New Event (MS, "Mix"), New Event (Sun, "Java Event")}; Var Microsoft Filter = New Filter & lt; Event & gt; (E = & gt; E Category Category == ms.CategoryId); Var microsoftEvents = FilterEvents (events, MicrosoftFilter); Console.Out.WriteLine (microsoftEvents.Count); } Public static list & lt; Event & gt; Filter events (list & lt; Event & gt; Events, Filters & lt; Event & gt; Filters) {Return Event.FundAul (E => Filters; dissatisfied (E)); }} Public Category Filter & lt; T & gt; Where T: class {private readonly pedicate & lt; T & gt; Criteria; Public Filter (valid Standards) {this.criteria = Criteria; } Public child dissatisfaction (T-OBJ) {return criteria (OBJ); }} Public class event {public event (category category, string name) {classId = category.CategoryId; Name = name; } Public Int Category IID {Received; Set; } Public string name {get; Set; }} Category of public class {public category (integer category id, string name) {classId = classId; Name = name; } Public string name {get; Set; } Public Int Category IID {Received; Set; }}
Comments
Post a Comment