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));
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            List <Person> persons = new List <Person>();

            persons.Add(new Person("Bob", "Male", "Single"));
            persons.Add(new Person("Bobbie", "Female", "Single"));
            persons.Add(new Person("Jim", "Male", "Married"));
            persons.Add(new Person("Jenny", "Female", "Single"));
            persons.Add(new Person("Chris", "Male", "Single"));
            persons.Add(new Person("Heather", "Female", "Married"));
            persons.Add(new Person("Kim", "Female", "Single"));

            ICriteria male         = new CriteriaMale();
            ICriteria female       = new CriteriaFemale();
            ICriteria single       = new SingleCriteria();
            ICriteria singleMale   = new AndCriteria(single, male);
            ICriteria singleFemale = new AndCriteria(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 Females: ");
            PrintPersons(singleFemale.MeetCriteria(persons));
        }
        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));
        }
Esempio 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));
    }