title: How would I get all public properties of object faster than with PropertyInfo.GetValue()?
body: <p>I have the following generic code that iterates over <code>IEnumerable&lt;T&gt;</code> (assuming all objects are exactly of type <code>T</code>) and for each item it retrieves all properties values and appends them to a <code>StringBuilder</code>:</p>
  
  <pre><code>Type t = typeof(T);
  var properties = t.GetProperties();
  
  foreach (var item in list)
  {
      foreach (var property in properties)
      {
          object value = property.GetValue(item, null);
          // feed to StringBuilder
      }
  }
  </code></pre>
  
  <p>and btw the <code>IEnumerable</code> comes from a non-trivial Linq-To-Sql query.</p>
  
  <p>So I profile my code and find that of all my code 37,3% time is spent in <code>System.Data.Linq.SqlClient.ObjectReaderCompiler.ObjectReader.MoveNext()</code> and 31,59% time is spent in <code>RuntimePropertyInfo.GetValue()</code>.</p>
  
  <p>This is why I'd be happy to find another way of retrieving all properties - one that is faster than calling <code>PropertyInfo.GetValue()</code>.</p>
  
  <p>How could I achieve that (preferable keeping the code generic)?</p>