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
Non-static methods are instance specific so you must instantiate the class to invoke the method. If you have the ability to change the code where it is defined and the method doesn't require itself to be part of an instance (it doesn't access or modify any non-static properties or methods inside the class) then best practice would be to make the method static anyway.
Assuming you can't make it static then the code you need is as follows:
foreach (Type t in types)
{
object instance = Activator.CreateInstance(t);
MethodInfo[] methods = t.GetMethods();
foreach (MethodInfo method in methods)
{
method.Invoke(instance, params...);
}
}