激活器和静态类 [英] Activator and static classes
问题描述
我正在讨论使用Activator类的想法,以便获得程序集中的资源,否则我将为其创建循环引用(依赖注入)。我之前已经使用需要引用的原始类完成了此操作,但是我的问题是:我可以使用Activator来访问静态类吗?
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让我烦恼的部分是,激活器会向您返回对象的 instance ,而静态类没有实例。
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?
推荐答案
您不需要激活程序来调用该方法。您直接使用 MethodInfo.Invoke 。第一个参数可以保留为空。
You do not need the Activator to call the method. You use MethodInfo.Invoke directly. The first parameter can be left null.
这篇关于激活器和静态类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!