c# - Using a ClassName as a parameter -
this question has answer here:
- convert string type in c# [duplicate] 4 answers
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
Post a Comment