title: Can TKey be inferred?
body: <p>I've created a validator that checks an <code>IList&lt;T&gt;</code> for duplicates. I came up with the following implementation:</p>
  
  <pre><code>namespace ConsoleApplication1
  {
      class Program
      {
          static void Main(string[] args)
          {
              var bar = new Foo() {Bar = "buzz"};
              var list = new List&lt;Foo&gt;() { }; //Foo has a property named Bar of type string
              var validator = new Validator&lt;Foo, string&gt;(x =&gt; x.Bar); //I have to specify the type of Bar
              validator.IsValid(list);
          }
      }
  }
  
  public class Foo
  {
      public string Bar { get; set; }
  }
  
  public class Validator&lt;T, Tkey&gt;
  {
      private readonly Func&lt;T, Tkey&gt; _keySelector;
  
      public Validator(Func&lt;T, Tkey&gt; keySelector)
      {
          _keySelector = keySelector;
      }
  
      public bool IsValid(IList&lt;T&gt; list)
      {
          if (list != null &amp;&amp; list.Count &gt; 0)
          {
              if (list.GroupBy(_keySelector).Any(g =&gt; g.Count() &gt; 1))
              {
                  return false;
              }
          }
  
          return true;
      }
  }
  </code></pre>
  
  <p>But I don't like how It has to be used: I have to specify the type of Bar during construction.</p>
  
  <p>The question is <strong>Can I somehow skip TKey when initializing Validator? Can it somehow be inferred?</strong></p>