title: Mapping umbraco node to strongtyped object
body: <p>I am working with Umbraco 4.7.1 and I am trying to map the content-nodes to some autogenerated strong typed objects. I have tried using both valueinjecter and automapper, but OOTB neither of them map my properties. I guess it is because all properties on an Umbraco node (the cms document) are retrieved like this:</p>
  
  <pre><code>node.GetProperty("propertyName").Value;
  </code></pre>
  
  <p>And my strongly typed objects are in the format of MyObject.PropertyName. So how do I map the property on the node which is retrieved using a method and a string beginning with a lowercase character into a property on MyObject where the property begins with an uppercase character ?</p>
  
  <p><strong>UPDATE</strong>
  I managed to create the following code which maps the umbraco node as intended, by digging around in the Umbraco sourcecode for some inspiration on how to cast string-properties to strongly typed properties:</p>
  
  <pre><code>    public class UmbracoInjection : SmartConventionInjection
  {
      protected override bool Match(SmartConventionInfo c)
      {
          return c.SourceProp.Name == c.TargetProp.Name;
      }
  
      protected override void Inject(object source, object target)
      {
          if (source != null &amp;&amp; target != null)
          {
  
              Node node = source as Node;
  
              var props = target.GetProps();
              var properties = node.Properties;
  
              for (int i = 0; i &lt; props.Count; i++)
              {
                  var targetProperty = props[i];
                  var sourceProperty = properties[targetProperty.Name];
                  if (sourceProperty != null &amp;&amp; !string.IsNullOrWhiteSpace(sourceProperty.Value))
                  {
                      var value = sourceProperty.Value;
                      var type = targetProperty.PropertyType;
                      if (targetProperty.PropertyType.IsValueType &amp;&amp; targetProperty.PropertyType.GetGenericArguments().Length &gt; 0 &amp;&amp; typeof(Nullable&lt;&gt;).IsAssignableFrom(targetProperty.PropertyType.GetGenericTypeDefinition()))
                      {
                          type = type.GetGenericArguments()[0];
                      }
                      targetProperty.SetValue(target, Convert.ChangeType(value, type));
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>As you can see I use the SmartConventionInjection to speed things up.
  It still takes approximately 20 seconds to map something like 16000 objects. Can this be done even faster ? </p>
  
  <p>thanks</p>
  
  <p>Thomas</p>