Tuesday, April 10, 2007

Calling Static Method Using Reflection

I was loading an assembly that contained a class that derived from a class which was defined in my assembly.  I wanted to call a static method in that assembly, so I used the Reflection GetMethod and Invoke calls.  Then I realized, that the static method was actully a static method of the class defined in my assembly.  So instead of using GetMethod and Invoke I could have just called the static method directly.


Would there be a difference? 


Turns out that the static method is executed in the assembly in which it is defined, regardless of whether or not GetMethod and Invoke are called or if the method is called directly.


0 Comments:

Post a Comment

<< Home