Hi there,
I have a collection of MyClass objects and i need to filter it by a combination of 17 fileds.
I implemented an object MyClassFilter with the 17 possible fields and the condition for each one and a method:
bool PassFilter(MyClass ObjectToEvaluate)
{
return PassFilterVal(this.Workstream, ObjectToEvaluate.WorkStream)
&& PassFilterVal(this.AssignedTo, ObjectToEvaluate.AssignedTo)
&& PassFilterVal(this.ProcessingGroup, ObjectToEvaluate.ProcessingGroup)
&& PassFilterVal(this.ScheduledStart, ObjectToEvaluate.ScheduledStart)
&& PassFilterVal(this.EntityName, ObjectToEvaluate.EntityName)
&& PassFilterVal(this.TaskIDs, ObjectToEvaluate.TaskID)
&& PassFilterVal(this.ElementIDs, ObjectToEvaluate.EntityID)
&& PassFilterVal(this.MappingIDs, ObjectToEvaluate.MappingID)
&& PassFilterVal(this.EntityStatus, ObjectToEvaluate.EntityStatus)
&& PassFilterVal(this.EntityType, ObjectToEvaluate.EntityType)
&& PassFilterVal(this.NumberOfSteps, ObjectToEvaluate.ListOfSteps.Count)
&& PassFilterVal(this.NumberOfDependancies, ObjectToEvaluate.ListOfParentDependancies.Count)
&& PassFilterVal(this.NumberOfOpenIssues, ObjectToEvaluate.ListOfAllIssues.CountOpen)
&& PassFilterVal(this.NumberOfRequirementsLinked, ObjectToEvaluate.RequierementsLinked)
;
}
and my collection has a method
ListOfMyClass FilterList(MyClassFilter Filter){
ListOfMyClass FilteredList = new ListOfMyClass();
foreach (MyClass Task in this)
{
if (Filter.TaskPassFilter(Task))
FilteredList.Add(Task);
}
return FilteredList;
}
It works fine as long as the collection is small but when I have 500 objects it start to be really slow. I have searched the net but all the examples are going object by object in the collection and asking filed by field if it pass or not.
Any suggestions as how to improve performance?
Thanks