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; }
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; }