How to invoke static generic class methods if the generic type parameters are unknown until runtime?
<p>Assume I have a static generic class.
Its generic type parameters are not available until runtime.
How to invoke its members?</p>

<p>Please see the following code snippet:</p>

<pre><code>static class Utility&lt;T&gt;
{
    public static void DoSomething() { }
}   

class Tester
{
    static Type GetTypeAtRuntime()
    {
      // return an object of type Type at runtime.
    } 
    static void Main(string[] args)
    {


        Type t = GetTypeAtRuntime();

        // I want to invoke Utility&lt;&gt;.DoSomething() here. How to do this?

    }
}
</code></pre>

<p>Edit:</p>

<p>OK, this is the solution based on the responses given by two guys below. Thanks for both of you!</p>

<pre><code> static class Utility&lt;T&gt;
{
    //Trivial method
    public static void DoSomething(T t) { Console.WriteLine(t.GetType()); }
}

// assume Foo is unknown at compile time.
class Foo { }

class Tester
{

    static void Main(string[] args)
    {

        Type t = typeof(Foo);// assume Foo is unknown at compile time.

        Type genType = typeof(Utility&lt;&gt;);

        Type con = genType.MakeGenericType(new Type[] { t });

        MethodInfo mi = con.GetMethod("DoSomething", BindingFlags.Static | BindingFlags.Public);

        mi.Invoke(null, new object[] { Activator.CreateInstance(t) });

    }
}
</code></pre>
