title: Reading a property value with a lambda expression
body: <p>I'm writing a file generic block for my application and started with using Lambda expressions for managing my rule sets for block generation to avoid the pitfalls of magic strings, configuration hell etc.</p>
  
  <p>Inside my mapping class I have lines similar to:</p>
  
  <pre><code>Map(x =&gt; x.Name).Length(20).PadLeft(true).PaddingChar("#");
  </code></pre>
  
  <p>This works fine and isn't where my question dwells, where I setup saving my information about the expression is in the Map method:</p>
  
  <pre><code>public override IPropertyMap Map(Expression&lt;Func&lt;T, object&gt;&gt; expression)
  {
      var propertyMap = new FixedLengthPropertyMap
            {
                //Length = 20,
                //PaddingCharacter = " ",
                PadLeft = false,
                PropertyInfo = ReflectionHelper.GetProperty(expression)
            };
  
      _properties.Add(propertyMap);
  
      return propertyMap;
  }
  </code></pre>
  
  <p><code>_properties</code> is just a <code>List&lt;IPropertyMap&gt;</code> that stores my info where my question from what is the best way to have a real object's data be read from the properties currently I came up with something similar to this:</p>
  
  <pre><code>var map = new AgentMap();
  var agent = new Agent {Name = "Bob"};
  
  string output = map.Write(agent);
  
  public override string Write&lt;T&gt;(T agent)
  {
      var initial = _properties[0];
      return initial.PropertyInfo.GetValue(agent, null) as string;
  }
  </code></pre>
  
  <p>Is there a better way than using the GetValue method since earlier on I'm using an expression tree?</p>