.NET Reflection: How to call method of interface without creating instance?

Posted by jitm on Stack Overflow See other posts from Stack Overflow or by jitm
Published on 2010-05-07T13:39:17Z Indexed on 2010/05/07 13:58 UTC
Read the original article Hit count: 233

Filed under:
|
|

I have situation where I have to call method of interface using reflection, like this

object x = null;
MethodInfo method = interfaceExists.GetMethod("ShutDown");
method.Invoke(x, new object[] { 4 })

As you can see I do not create instance of object! And, as I can supposed, I receive exception

Non-static method requires a target

And Question, Can I call method of interface using reflection without creating instance of interface and if YES, How I can do it ?

© Stack Overflow or respective owner

Related posts about c#

Related posts about reflection