.net - Run all methods in a class C# -
i have class on 200 functions. need have function run of methods in class.
all of functions return void
, , take no parameters.
this have:
public void runallfunctions() { var methods = typeof(win10).getmethods(bindingflags.public | bindingflags.instance); object[] parameters = null; foreach (var method in methods) { if (method.name.startswith("wn10")) { method.invoke(null, parameters); } } }
with code, error "non-static method requires target"
how can run of methods?
you have provide win10
class instance; if runallfunctions
method of win10
:
public void runallfunctions() { var methods = gettype() .getmethods(bindingflags.public | bindingflags.instance) .where(item => item.name.startswith("wn10")); foreach (var method in methods) method.invoke(this, new object[0]); // please, notice "this" }
in case runallfunctions
not method of win10
:
public void runallfunctions() { win10 instance = new win10(); //todo: put right constructor here var methods = instance .gettype() .getmethods(bindingflags.public | bindingflags.instance) .where(item => item.name.startswith("wn10")); foreach (var method in methods) method.invoke(instance, new object[0]); }
Comments
Post a Comment