title: C# Using GetProperty for LINQ OrderBy using FileInfo
body: <p>I am trying to use the <em>Reflection</em> <code>GetProperty</code> to set the type of <code>OrderBy</code> I want <em>dynamically</em>. The <code>orderByParam</code> would have a value such as <code>"Length"</code>, <code>"Name"</code>, <code>"CreationTime"</code>, etc. This will allow me to add the files to a list in the order I want later on. The <strong>error</strong> I am receiving is: </p>
  
  <blockquote>
    <p>Object does not match target type</p>
  </blockquote>
  
  <p>. What am I missing here?</p>
  
  <pre><code>try
  {
      PropertyInfo propertyInfo = typeof(FileInfo).GetProperty(orderByParam);
      var files = Directory.GetFiles(strPath)
                           .OrderBy(f =&gt; propertyInfo.GetValue(orderByParam, null));  
                           //FileInfo(f).CreationTime))
  
      foreach (string str in files)
      {
          strFiles.Add(Path.GetFileName(str));
      }
  }
  </code></pre>