Вызов статического метода с отражением
У меня есть несколько статических классов в пространстве именmySolution.Macros
такие как
static class Indent{
public static void Run(){
// implementation
}
// other helper methods
}
So my question is how it will be possible to call those methods with the help of reflection?
Если методы, где НЕ быть статичными, то я мог бы сделать что-то вроде:
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);
}
Я хотел бы сохранить мои классы статичными. Как я смогу сделать что-то подобное со статическими методами?
In short Я хотел бы вызвать все методы Run из всех статических классов, которые находятся в пространстве имен mySolution.Macros.