c#: how to convert string to custom template type (i.e. implement "T convertTo<T>(string)")
<p>I want a function that can convert "string" to a given type T.
I.e. I want to implement such function:</p>

<pre><code>T convertTo&lt;T&gt;(string stringToConvert)
</code></pre>

<p>T could be actually either simple type or enum, but i don't know how to check actual T type at runtime. I.e. I can't write something like that:</p>

<pre><code>if (T instanceof MyEnum) { return MyEnum.Parse(stringToConvert); }
</code></pre>

<p>How can I implement my function then?</p>
