title: Casting interface type in Lazy<T>
body: <p>I want something like this:</p>
  
  <pre><code>public interface IAnimal
  { }
  
  public class Dog : IAnimal
  {
      public Dog() {}
  }
  
  public class Cat : IAnimal
  {
      public Cat() {}
  }
  
  public abstract class TestClassBase
  {
      public TestClassBase()
      {
          _lazyAnimal = CreateLazyAnimal();
      }
  
      private Lazy&lt;IAnimal&gt; _lazyAnimal = null;
      public IAnimal Animal
      {
          get
          { 
              IAnimal animal = null;
              if (_lazyAnimal != null)
                  animal = _lazyAnimal.Value;
  
              return animal;
          }
      }
  
      // Could be overridden to support other animals
      public virtual Lazy&lt;IAnimal&gt; CreateLazyAnimal()
      {
          // default animal is a dog
          return new Lazy&lt;Dog&gt;(); // this type of casting doesn't work and I don't know a good workground
      }
  }
  </code></pre>
  
  <p>I know from tinkering with MEF that it manages to find and store different types, implementing a single interface, into Lazy&lt;T&gt;. Just not sure how to do it myself.</p>