Wywołaj metodę statyczną z odbiciem
Mam kilka klas statycznych w przestrzeni nazwmySolution.Macros
Jak na przykład
static class Indent{
public static void Run(){
// implementation
}
// other helper methods
}
Moje pytanie brzmi: jak będzie można nazwać te metody za pomocą refleksji?
Jeśli metody, które NIE mają być statyczne, mógłbym zrobić coś takiego:
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);
}
Chciałbym, aby moje klasy były statyczne. Jak będę mógł zrobić coś podobnego za pomocą metod statycznych?
W skrócie Chciałbym wywołać wszystkie metody Run ze wszystkich klas statycznych znajdujących się w przestrzeni nazw mySolution.Macros.