title: Custom Mapping with AutoMapper
body: <p>I have two very simple objects:</p>
  
  <pre><code>public class CategoryDto
  {
      public string Id { get; set; }
  
      public string MyValueProperty { get; set; }
  }
  
  public class Category
  {
      public string Id { get; set; }
  
      [MapTo("MyValueProperty")]
      public string Key { get; set; }
  }
  </code></pre>
  
  <p>When mapping a <code>Category</code> to a <code>CategoryDto</code> with AutoMapper, I would like the following behavior:  </p>
  
  <p>The properties should be mapped as usual, except for those that have the <code>MapTo</code> attribute. In this case, I have to read the value of the Attribute to find the target property. The value of the source property is used to find the value to inject in the destination property (with the help of a dictionary). An example is always better that 1000 words...</p>
  
  <p>Example:</p>
  
  <pre><code>Dictionary&lt;string, string&gt; keys = 
      new Dictionary&lt;string, string&gt; { { "MyKey", "MyValue" } };
  
  Category category = new Category();
  category.Id = "3";
  category.Key = "MyKey";
  
  CategoryDto result = Map&lt;Category, CategoryDto&gt;(category);
  result.Id               // Expected : "3"
  result.MyValueProperty  // Expected : "MyValue"
  </code></pre>
  
  <p>The <code>Key</code> property is mapped to the <code>MyValueProperty</code> (via the <code>MapTo</code> Attribute), and the assigned value is "MyValue", because the source property value is "MyKey" which is mapped (via dictionary) to "MyValue".</p>
  
  <p>Is this possible using AutoMapper ? I need of course a solution that works on every object, not just on Category/CategoryDto.</p>