title: Automapper with custom lazy loading objects
body: <p>I have a <code>Person</code> class which contains a property that lazy loads (custom made lazy loading) the person address data through accessing the <code>Item</code> property. I would want it to be mapped to a POCO class. How could it be done?</p>
  
  <p>In addition, is it possible to be mapped only if it has data (checking the <code>HasData</code> property) and mapped as <code>null</code> if there isn’t data?.
  These are the source classes:</p>
  
  <pre><code>public class SourcePerson
  {
      public string Name { get; set; }
  
      public MyLazyLoadingObject&lt;SourceAddress&gt; Address;
  }
  
  public class SourceAddress
  {
      public string City { get; set; }
  
      public string Country { get; set; }
  }
  </code></pre>
  
  <p>This is the custom lazy loading class (simplified):</p>
  
  <pre><code>public class MyLazyLoadingObject&lt;T&gt;
  {
      private int? _id;
      private T _object;
  
      public T Item
      {
          get
          {
              if (!_object.IsReaded)
              {
                  _object.Read();
              }
  
              return _object;
          }
      }
  
      public bool HasData
      {
          get
          {
              return _id.HasValue;
          }
      }
  
      // Other non-relevant properties and methods 
  }
  </code></pre>
  
  <p>These are the destination classes:</p>
  
  <pre><code>public class DestinationPerson
  {
      public string Name { get; set; }
  
      public DestinationAddress Address;
  }
  
  public class DestinationAddress
  {
      public string City { get; set; }
  
      public string Country { get; set; }
  }
  </code></pre>