title: How can I create an Automapper extension method to perform a mapping on all properties of a certain type?
body: <p>I want to create an Automapper extension method that performs a custom mapping on all properties of a certain type. Here is some pseudocode demonstrating what I want:</p>
  
  <pre><code>public static IMappingExpression&lt;TSource, TDestination&gt; UnflattenMembers&lt;TSource, TDestination&gt;
          (this IMappingExpression&lt;TSource, TDestination&gt; map)
      {
          foreach (property of the TSource Class)
          {
              if (property is of Type SpecialClass)
              {
                  map.ForMember(dest =&gt; dest.property, opt =&gt; opt.MapFrom(src =&gt; src));
              }
          }
          return map;
      }
  </code></pre>
  
  <p>I want to do this to achieve a generic implementation of sydneyos's answer to this question: <a href="https://stackoverflow.com/questions/3145062/using-automapper-to-unflatten-a-dto">Using AutoMapper to unflatten a DTO</a>.</p>
  
  <p>E.g., Instead of doing this:</p>
  
  <pre><code>Mapper.CreateMap&lt;SourceClass, DestClass&gt;()
      .ForMember(dest =&gt; dest.Address, opt =&gt; opt.MapFrom( src =&gt; src )))
      .ForMember(dest =&gt; dest.MailingInfo, opt =&gt; opt.MapFrom( src =&gt; src )))
      .ForMember(dest =&gt; dest.Calendar, opt =&gt; opt.MapFrom( src =&gt; src )))
      etc...;
  </code></pre>
  
  <p>I want to to this:</p>
  
  <pre><code>Mapper.CreateMap&lt;SourceClass, DestClass&gt;().UnflattenMembers();
  </code></pre>