示例#1
0
        private Farm BuildFarm()
        {
            var farm = new Farm();

            var rex = new Dog();
            rex.Name = "Rex";
            rex.Birthday = new DateTime(2009, 10, 22);
            farm.Animals.Add(rex);

            var tom = new Cat();
            tom.Name = "Tom";
            tom.Birthday = new DateTime(1940, 6, 15);
            farm.Animals.Add(tom);

            var jerry = new Mouse();
            jerry.Name = "Jerry";
            farm.Animals.Add(jerry);

            return farm;
        }
示例#2
0
文件: Farm.cs 项目: paulomouat/spikes
        protected override object ElementWasFound(string name)
        {
            Animal animal = null;

            switch (name)
            {
                case "Dog":
                    animal = new Dog();
                    break;
                case "Cat":
                    animal = new Cat();
                    break;
                case "Mouse":
                    animal = new Mouse();
                    break;
            }

            Animals.Add(animal);

            return animal;
        }