title: Is it possible to restrict the type of variable passed to a .NET method to not be a derived class?
body: <p>Can i constrain the type that is passed to my method in a way that catches this type of error when compiling instead of running?</p>
  
  <p>My current code looks like this:</p>
  
  <pre><code>void Main()
  {
      var dog = new Dog();
      SaveAnimal(dog);
  }
  
  void SaveAnimal(Animal animal) {
      var isAnimal = animal.GetType().UnderlyingSystemType == typeof(Animal);
      Debug.Assert(isAnimal, "You can not save dogs!");
  }
  
  class Animal {
      public int Legs { get; set; }
  }
  
  class Dog : Animal {
      public int TailLength { get; set; }
  }
  </code></pre>