Suppose I have an instance of a class that contains several methods. I also have a textual representation of a function call for a method in that class. For example, the string might be SomeMethod(5, "hello")
. I am looking to translate any given valid string into the appropriate method call.
So far I've been able to access the method by parsing the method name and then calling GetType().GetMethod(method_name)
on the instance of the class. However, I am having difficulty with fulfilling the method signature. I can access the types of the method parameters using MethodBase.GetParameters()
, but I would have to know the types to cast at compile time to make the function call valid.
I also have the feeling that my entire approach may be wrong. Is there a common pattern for accomplishing this?
Aucun commentaire:
Enregistrer un commentaire