I'm attempting to write a utility method which should be capable of executing any method. Consider this for example. I have a class with the following methods:
ClassA
void Method1 (int a)
void Method2 (int b, string s, long l)
Object Method3 (string a, Object o)
List<string> Method4 (double d, List<string> sList)
Now, in a different class, I have a method execute
ClassB
void execute (string methodName, Map<string, object> params)
methodName
will contain the required method's name (Method1/Method2/Method3/Method4) and params
will have the parameters to be passed into the method. params
will be a dictionary object like these for Method1 to Method4 respectively:
<Key> <Value>
"int" 1
Or
"int" 2
"string" "test"
"long" 1234567896557
Or
"string" "abc"
"object" someClassObject
Or
"double" 456.764
"List<string,string>" someListObject
I know we can get the class and the methods through reflection, but is it possible to get the parameters to those methods? Along with the methods, I need to know what parameters (types and values) need to be passed into that method, so that I can lookup the params dictionary object and pass the correct parameters into the method. I have heard about paranamer, but want to know if this is possible without any external jars?
Aucun commentaire:
Enregistrer un commentaire