Activator and static classes

japollock picture japollock · Mar 5, 2009 · Viewed 9.3k times · Source

I'm tossing around the idea of using the Activator class in order to get access to resources in an assembly that I would otherwise create a circular reference for (dependency injection). I've done it before with vanilla classes that I needed a reference to, but my question is: can I use the Activator to get access to a static class?

The part that's tripping me up is that the Activator returns to you a instance of the object, whereas a static class has no instance. Is this possible?

Answer

GvS picture GvS · Mar 5, 2009

You do not need the Activator to call the method. You use MethodInfo.Invoke directly. The first parameter can be left null.