title: How can I use Automapper to map an object to an unknown destination type?
body: <p>Consider the following scenario.  I have a number of classes that share a common base class and I have defined an automapper mapping for each derived class.  Something like this:</p>
  
  <pre><code>class A : Base {}
  
  class B : Base {}
  
  class ContractA : ContractBase {}
  
  class ContractB : ContractBase {}
  
  void Foo()
  {
      Mapper.CreateMap&lt;A, ContractA&gt;();
      Mapper.CreateMap&lt;B, ContractB&gt;();
  }
  </code></pre>
  
  <p>So far so good.  But now I want to create a method like this:</p>
  
  <pre><code>ContractBase Foo()
  {
      Base obj = GetObject();
  
      return Mapper.???
  }
  </code></pre>
  
  <p>The problem is that all of AutoMapper's Map variants require that I either know the destination type at compile time or have an object of that type available at runtime.  This is seriously frustrating since I have defined only one map for each source type.  AutoMapper should be able to infer the destination type given only the source type.</p>
  
  <p>Is there any good way around this?  I want to avoid creating a dictionary mapping source types to destination types.  While this would work, it would mean that I'd essentially have to define two mappings for every source type.</p>