title: LINQ OrderBy with index ; getting error using Generic TKey
body: <p>I am trying to order an <code>IEnumerable&lt;MyClass&gt;</code> based on the index of the selected property:</p>
  <pre><code>class MyClass 
  {
   public string Name;
   public string Value;
  }
  </code></pre>
  <p>I have a helper method to get an <code>Expression&lt;&gt;</code> of the criteria.<br />
  It is compiled to create the <code>Func&lt;&gt;</code> to help with the ordering.<br />
  I'm having trouble trying to make the <code>Func&lt;&gt;</code> return a Generic <code>TKey</code> to be ordered.</p>
  <pre><code>public Expression&lt;Func&lt;T, TKey&gt;&gt; Helper&lt;T&gt;(int propIdx)
  {
      var param = Expression.Parameter(typeof(T), &quot;record&quot;);
      var props = typeof(T).GetProperties();
  
      if(propIdx &gt; props.Count()) 
          return Expression.Lambda&lt;Func&lt;T, TKey&gt;&gt;)(Expression.Constant(true), param);
  
      Expression propExp = Expression.Property(param, props[propIdx].Name);
  
      return lambda = Expression.Lambda&lt;Func&lt;T, TKey&gt;&gt;(propExp, param);
  }
  </code></pre>
  <p>This is used to help with dynamic order criteria.</p>
  <pre><code>OrderByIdx(IEnumerable&lt;MyClass&gt; input, int propIdx)
  {
       Expression&lt;Func&lt;T, TKey&gt;&gt; exp = Helper(propIdx);
       
       var funct = exp.Compile();
  
       return input.OrderBy(funct);
  }
  </code></pre>
  <p>I am getting an error <code>The type or namespace TKey could not be found</code></p>
  <p>How can I use a Generic<code>&lt;TKey&gt;</code> to help with the ordering ?</p>