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));
        }
Ejemplo n.º 2
0
        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;
        }
Ejemplo n.º 3
0
        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));
        }
Ejemplo n.º 4
0
    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));
    }