I want to invoke methods with a certain attribute.
So I'm cycling through all the assemblies and all methods to find the methods with my attribute. Works fine, but how do I invoke a certain method when I only got it's MethodInfo.
AppDomain app = AppDomain.CurrentDomain;
Assembly[] ass = app.GetAssemblies();
Type[] types;
foreach (Assembly a in ass)
{
types = a.GetTypes();
foreach (Type t in types)
{
MethodInfo[] methods = t.GetMethods();
foreach (MethodInfo method in methods)
{
// Invoke a certain method
}
}
}
The problem is that I don't know the instance of the class that contains that certain method. So I can't invoke it properly because the methods are not static.
I also want to avoid creating a new instance of this class if possible.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…