mercredi 30 septembre 2015

Using a ClassName as a parameter in C#

I have searched the current questions and none seemed to solve my particular issue.

I have several classes that contain validation methods in them : ClientValidation, PaymentValidation, etc. The plan is to dynamically build a list of methods that I would use to validate a record. To do this I need to be able to get a list of the methods contained within each class. To do that I have written the following line:

var methods = typeof( ClientValidation ).GetMethods();

This works great if all my methods were under the ClientValidation class, but they are not. What I want to be able to do is be able to dynmically pass in the class name so the line could look more like:

var dynamicClassName = GetClassNameMethod();

var methods = typeof( dynamicClassName ).GetMethods();

Is this possible? How would I do this?

Thanks in advance.





Aucun commentaire:

Enregistrer un commentaire