Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>First off, stop thinking of generic methods as templates. They are NOT templates. They have very different behaviour from templates; your expectation that they behave like templates is possibly what is leading you astray in this situation.</p> <p>Here is a series of articles I wrote about your scenario and why it is illegal.</p> <p><a href="http://blogs.msdn.com/ericlippert/archive/2007/06/14/calling-static-methods-on-type-variables-is-illegal-part-one.aspx" rel="nofollow noreferrer">http://blogs.msdn.com/ericlippert/archive/2007/06/14/calling-static-methods-on-type-variables-is-illegal-part-one.aspx</a></p> <p><a href="http://blogs.msdn.com/ericlippert/archive/2007/06/18/calling-static-methods-on-type-variables-is-illegal-part-two.aspx" rel="nofollow noreferrer">http://blogs.msdn.com/ericlippert/archive/2007/06/18/calling-static-methods-on-type-variables-is-illegal-part-two.aspx</a></p> <p><a href="http://blogs.msdn.com/ericlippert/archive/2007/06/21/calling-static-methods-on-type-variables-is-illegal-part-three.aspx" rel="nofollow noreferrer">http://blogs.msdn.com/ericlippert/archive/2007/06/21/calling-static-methods-on-type-variables-is-illegal-part-three.aspx</a></p> <p>Note that of course the "dynamic" feature that I hint at in part three is in fact shipping with C# 4.0.</p> <p>To address your actual question: "what's the best way to do this?" Presumably you have some problem which you believe a mechanism like this would solve. This mechanism doesn't actually exist in C#. <strong>It is impossible for us to deduce what problem you are actually trying to solve from the fact that you would like this mechanism to exist.</strong> Instead of asking "how can I make this impossible thing work in C#?" instead <strong>describe the real problem you have</strong>, and we can take a crack at trying to come up with an existing C# mechanism that better solves your real problem.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload