Invoking static methods containing Generic Parameters using Reflection.

Posted by AJP on Stack Overflow See other posts from Stack Overflow or by AJP
Published on 2010-06-16T10:18:39Z Indexed on 2010/06/16 10:22 UTC
Read the original article Hit count: 169

Filed under:
|
|

While executing the following code i gets this error "Late bound operations cannot be performed on types or methods for which ContainsGenericParameters is true."

class Program
{
    static void Main(string[] args)
    {
        MethodInfo MI = typeof(MyClass).GetMethod("TestProc");
        MI.MakeGenericMethod(new [] {typeof(string)});
        MI.Invoke(null, new [] {"Hello"});
    }
}

class MyClass
{
    public static void TestProc<T>(T prefix) 
    {
        Console.WriteLine("Hello");
    }
}

Please help.

© Stack Overflow or respective owner

Related posts about c#

Related posts about generics