Dynamic assembly loading with static functions

Hello,
I have a program which is dynamically loading in several assemblies. So what I am doing is creating instances of the assemblies just to extract some data (constants).


obj = Activator.CreateInstance(typeTemp);
//Create the instance then typecast it to access some method

 


But what I want to do is to access a static function instead of having to create an instance of the class and calling the method. Is there a way to dynamically invoke a static method with no instance of the type

Thanks,
Mish




Answer this question

Dynamic assembly loading with static functions

  • S2

    Sure, you just need a reference to the assembly (type System.Reflection.Assembly).  On the assembly reference you can call GetType with the name of the type that defines your static method; this returns a System.Reflection.Type reference.  Then you call InvokeMember on the type reference, with BindingFlag.Static and any other required parameters (see MSDN).
  • Dynamic assembly loading with static functions