title: Type inference for fluent API
body: <p>I have the following extension methods:</p>
  
  <pre><code>public static IFoo Foo(this IFluentApi api, Action action);
  
  public static IFoo&lt;TResult&gt; Foo&lt;TResult&gt;(
      this IFluentApi api, Func&lt;TResult&gt; func);
  
  public static IBar Bar(this IFoo foo);
  
  public static void FooBar(this IBar bar, Action action);
  
  public static void FooBar&lt;TResult&gt;( // &lt;- this one cannot work as desired 
      this IBar bar, Action&lt;TResult&gt; action);
  </code></pre>
  
  <p>The generic interfaces are always derived from their corresponding non-generic interface.</p>
  
  <p>Unfortunately, to make this work:</p>
  
  <pre><code>api.Foo(x =&gt; ReturnLong())
     .Bar()
     .FooBar(x =&gt; ...); // x should be of type long
  </code></pre>
  
  <p>I need to also implement the following extension method:</p>
  
  <pre><code>public static IBar&lt;TResult&gt; Bar&lt;TResult&gt; (this IFoo&lt;TResult&gt; foo);
  </code></pre>
  
  <p>and change the last of the above extension methods to:</p>
  
  <pre><code>public static void FooBar&lt;TResult&gt;(
      this IBar&lt;TResult&gt; bar, Action&lt;TResult&gt; action);
  </code></pre>
  
  <p>As I actually not only have <code>Bar()</code> between <code>Foo()</code> and <code>FooBar()</code> but a VERY long chain of methods I would have huge additional implementation costs.</p>
  
  <p>Is there any way to avoid this problem and "magically" forward the <code>TResult</code> generic parameter? </p>
  
  <p><strong>Edit:</strong> </p>
  
  <p>Without losing type inference!</p>