Exemple #1
0
        public void Food(Type[] animals, AnimalFlags animalFlags)
        {
            Console.WriteLine("Человек кормит живность...");
            AnimalFlags tempFlag = AnimalFlags.none;
            IEnumerator type     = animals.GetEnumerator();

            while (type.MoveNext())
            {
                if ((type.Current as Type).Name == "Cat")
                {
                    tempFlag = animalFlags & AnimalFlags.Cat;
                }
                if ((type.Current as Type).Name == "Duck")
                {
                    tempFlag = animalFlags & AnimalFlags.Duck;
                }
                switch (tempFlag)
                {
                case AnimalFlags.Cat:
                    IAnimals cat = Activator.CreateInstance((type.Current as Type)) as IAnimals;
                    cat.Eat();
                    break;

                case AnimalFlags.Duck:
                    IAnimals duck = Activator.CreateInstance((type.Current as Type)) as IAnimals;
                    duck.Eat();
                    break;
                }
            }
        }
Exemple #2
0
        static void Main(string[] args)
        {
            Assembly assembly = null;

            Type[] animals = null;
            try
            {
                assembly = Assembly.Load("HT01_AnimalsLib");
                animals  = assembly.GetTypes();
            }
            catch (FileNotFounException e)
            {
                Console.WriteLine(e.Message);
            }

            Console.WriteLine("Введите живность для кормления");
            string str = Console.ReadLine().ToLower();

            AnimalFlags flag = AnimalFlags.none;

            if (str.Contains("утк") == true)
            {
                flag = AnimalFlags.Duck;
            }
            if (str.Contains("кошк") == true || str.Contains("кот") == true)
            {
                flag = flag | AnimalFlags.Cat;
            }

            Human human = new Human();

            if (animals != null)
            {
                human.Food(animals, flag);
            }
        }