title: How to lazy load a property with custom attribute
body: <p>I want to create a custom attribute using Glass Mapper for getting the Sitecore URL, because it is not possible to lazy load a property with <code>SitecoreInfo(SitecoreInfoType.Url)</code> and we have some performance issues loading URL of mapped items, where the URL will never be used.</p>
  
  <p>Here is what I've got so far:</p>
  
  <h2>The Configuration</h2>
  
  <pre><code>public class SitecoreUrlConfiguration : AbstractPropertyConfiguration
  {
      public SitecoreInfoUrlOptions UrlOptions { get; set; }
  
      public bool IsLazy { get; set; }
  }
  </code></pre>
  
  <h2>The Attribute</h2>
  
  <pre><code>public class SitecoreUrlAttribute : AbstractPropertyAttribute
  {
      public SitecoreUrlAttribute()
      {
          this.IsLazy = true;
          this.UrlOptions = SitecoreInfoUrlOptions.Default;
      }
  
      /// &lt;summary&gt;
      /// Gets or sets a value indicating whether is lazy.
      /// &lt;/summary&gt;
      public bool IsLazy { get; set; }
  
      public SitecoreInfoUrlOptions UrlOptions { get; set; }
  
      public override AbstractPropertyConfiguration Configure(PropertyInfo propertyInfo)
      {
          var config = new SitecoreUrlConfiguration();
          this.Configure(propertyInfo, config);
          return config;
      }
  
      public void Configure(PropertyInfo propertyInfo, SitecoreUrlConfiguration config)
      {
          config.UrlOptions = this.UrlOptions;
          config.IsLazy = this.IsLazy;
  
          base.Configure(propertyInfo, config);
      }
  }
  </code></pre>
  
  <h2>The Mapper</h2>
  
  <pre><code>public class SitecoreUrlMapper : AbstractDataMapper
  {
      public override object MapToProperty(AbstractDataMappingContext mappingContext)
      {
          var context = mappingContext as SitecoreDataMappingContext;
          if (context == null)
          {
              throw new MapperException("Mapping Context is null");
          }
  
          var item = context.Item;
          var scConfig = this.Configuration as SitecoreUrlConfiguration;
  
          if (scConfig == null)
          {
              throw new MapperException("SitecoreUrlConfiguration is null");
          }
  
          var urlOptions = Utilities.CreateUrlOptions(scConfig.UrlOptions);
  
          urlOptions.Language = null;
          // now, what?
      }
  }
  </code></pre>
  
  <p>So far, so good. But how can I lazy load the URL in the mapper? Does anyone have an idea?</p>