c# - Using a ClassName as a parameter -


this question has answer here:

i have several classes contain validation methods in them : clientvalidation, paymentvalidation, etc. plan dynamically build list of methods use validate record. need able list of methods contained within each class. have written following line:

var methods = typeof( clientvalidation ).getmethods(); 

this works great if methods under clientvalidation class, not. want able able dynmically pass in class name line more like:

var dynamicclassname = getclassnamemethod();  var methods = typeof( dynamicclassname ).getmethods(); 

is possible? how this?

you can this:

var methods = type.gettype(full_class_name).getmethods(); 

where full_class_name full class name (with namespace). example: "consoleapplication1.class1".

if want use class name without namespace (e.g. "class1"), can search assembly such class this:

var methods = assembly.getexecutingassembly().gettypes().first(x => x.name == class_name).getmethods(); 

where class_name class name "class1".


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

excel - I can't get the attachement of the email PHP -

node.js - Express and Redis - If session exists for this user, don't allow access -