示例#1
0
 public static void GiveFood(Mammal mammal)
 {
     for (
         var currentType = mammal.GetType();
         typeof(Mammal).IsAssignableFrom(currentType);
         currentType = currentType.BaseType)
     {
         if (map.ContainsKey(currentType))
         {
             map[currentType](mammal);
             return;
         }
     }
     DefaultGiveFood(mammal);
 }
示例#2
0
 void feed(Mammal mammal)
 {
     Feeder.GiveFood(mammal);
 }
示例#3
0
 public static void DefaultGiveFood(Mammal mammal)
 {
     Console.WriteLine("Feeding an unknown mammal.");
 }
示例#4
0
 public static void Eat(Mammal animal)
 {
     animal.Eat();
 }
示例#5
0
 public static void GiveFood(Mammal mammal)
 {
     map[mammal.GetType()](mammal);
 }