public void Start() { var persons = new List <Person>() { new Person { Name = "Avinash", Gender = "Male", MaritalStatus = "Single" }, new Person { Name = "Pruthvi", Gender = "Male", MaritalStatus = "Single" }, new Person { Name = "Lakshmi", Gender = "Female", MaritalStatus = "Married" }, new Person { Name = "Manoj", Gender = "Male", MaritalStatus = "Single" }, new Person { Name = "Bharath", Gender = "", MaritalStatus = "Single" } }; var male = new CriteriaMale(); var female = new CriteriaFemale(); var single = new CriteriaSingle(); male.MeetCriteria(persons).DoAction(x => logger.Info("Males: ")).ForEach(m => logger.Info(m)); female.MeetCriteria(persons).DoAction(x => logger.Info("Females: ")).ForEach(f => logger.Info(f)); single.MeetCriteria(persons).DoAction(x => logger.Info("Single: ")).ForEach(s => logger.Info(s)); (new AndCriteria(single, male)).MeetCriteria(persons).DoAction(x => logger.Info("And: ")).ForEach(a => logger.Info(a)); (new OrCriteria(single, female)).MeetCriteria(persons).DoAction(x => logger.Info("Or: ")).ForEach(o => logger.Info(o)); }
private void btFilterPattern_Click(object sender, EventArgs e) { string str = ""; List <Person> persons = new List <Person>(); persons.Add(new Person("Robert", "Male", "Single")); persons.Add(new Person("John", "Male", "Married")); persons.Add(new Person("Laura", "Female", "Married")); persons.Add(new Person("Diana", "Female", "Single")); persons.Add(new Person("Mike", "Male", "Single")); persons.Add(new Person("Bobby", "Male", "Single")); ICriteria male = new CriteriaMale(); ICriteria female = new CriteriaFemale(); ICriteria single = new CriteriaSingle(); ICriteria singleMale = new AndCriteria(single, male); ICriteria singleOrFemale = new OrCriteria(single, female); str += "Males:\r\n "; str += printPersons(male.meetCriteria(persons)) + "\r\n"; str += "Females:\r\n "; str += printPersons(female.meetCriteria(persons)) + "\r\n"; str += "Single Males:\r\n "; str += printPersons(singleMale.meetCriteria(persons)) + "\r\n"; str += "Single Or Females:\r\n "; str += printPersons(singleOrFemale.meetCriteria(persons)) + "\r\n"; tbOutWindow.Text = str; }
public static void Start() { List <Person> persons = new List <Person>(); persons.Add(new Person("Robert", "Male", "Single")); persons.Add(new Person("John", "Male", "Married")); persons.Add(new Person("Laura", "Female", "Married")); persons.Add(new Person("Diana", "Female", "Single")); persons.Add(new Person("Mike", "Male", "Single")); persons.Add(new Person("Bobby", "Male", "Single")); Criteria male = new CriteriaMale(); Criteria female = new CriteriaFemale(); Criteria single = new CriteriaSingle(); Criteria singleMale = new AndCriteria(single, male); Criteria singleOrFemale = new OrCriteria(single, female); Console.WriteLine("Males: "); PrintPersons(male.MeetCriteria(persons)); Console.WriteLine("\nFemales: "); PrintPersons(female.MeetCriteria(persons)); Console.WriteLine("\nSingle Males: "); PrintPersons(singleMale.MeetCriteria(persons)); Console.WriteLine("\nSingle Or Females: "); PrintPersons(singleOrFemale.MeetCriteria(persons)); }
public void Main() { List <Person> persons = new List <Person>(); persons.Add(new Person("Robert", "Male", "Single")); persons.Add(new Person("John", "Male", "Married")); persons.Add(new Person("Laura", "Female", "Married")); persons.Add(new Person("Diana", "Female", "Single")); persons.Add(new Person("Mike", "Male", "Single")); persons.Add(new Person("Bobby", "Male", "Single")); ICriteria male = new CriteriaMale(); ICriteria female = new CriteriaFemale(); ICriteria single = new CriteriaSingle(); ICriteria singleMale = new AndCriteria(single, male); ICriteria singleOrFemale = new OrCriteria(single, female); PrintPersons(male.MeetCriteria(persons)); PrintPersons(female.MeetCriteria(persons)); PrintPersons(single.MeetCriteria(persons)); PrintPersons(singleMale.MeetCriteria(persons)); PrintPersons(singleOrFemale.MeetCriteria(persons)); }