我在命名空间中有几个静态类,mySolution.Macros例如
static class Indent{
public static void Run(){
// implementation
}
// other helper methods
}
所以我的问题是,在反射的帮助下如何调用这些方法?
如果方法不是静态的,那么我可以做些类似的事情:
var macroClasses = Assembly.GetExecutingAssembly().GetTypes().Where( x => x.Namespace.ToUpper().Contains("MACRO") );
foreach (var tempClass in macroClasses)
{
var curInsance = Activator.CreateInstance(tempClass);
// I know have an instance of a macro and will be able to run it
// using reflection I will be able to run the method as:
curInsance.GetType().GetMethod("Run").Invoke(curInsance, null);
}
我想让我的课保持静态。如何使用静态方法执行类似的操作?
简而言之,我想从名称空间mySolution.Macros中的所有静态类中调用所有Run方法。
C# 反射 动态
胡子哥哥
相关分类