dynamically invoking a method in an assemly
-
Hi everybody, I was given a job of developing a function which accepts 3 parameters i.e., an assembly path, a class with namespace, and a method in that assembly. the function should return the value that is being returned by the method that iam invoking(the one which we passed as a parameter) iam using system.reflection namespace. The problem is, i also need to pass arguements to the method that iam invoking but it is just not working the i way i want. this is how iam calling my function ..
public int myreflect("..the path of the assembly..", "...calss name with namespace..say N.C1..","..method name..say M1..", 2,4) // 2,4 are the arguments iam passing to my method M1//
This is how iam defining my functionpublic int myreflect(string a, string b, string c, params int[] list)
Everything is working except that i need to somehow extract the arguements which are in the param array i.e., list. I need to capture those arguments and store them in another array..say int[] args..and use this args in Invokemember function, as parameters to invoke my M1 method. I hope I have done a fair job in explaining my problem. A little help would be greatly appreciated. Thanks in advance....Sonu
-
Hi everybody, I was given a job of developing a function which accepts 3 parameters i.e., an assembly path, a class with namespace, and a method in that assembly. the function should return the value that is being returned by the method that iam invoking(the one which we passed as a parameter) iam using system.reflection namespace. The problem is, i also need to pass arguements to the method that iam invoking but it is just not working the i way i want. this is how iam calling my function ..
public int myreflect("..the path of the assembly..", "...calss name with namespace..say N.C1..","..method name..say M1..", 2,4) // 2,4 are the arguments iam passing to my method M1//
This is how iam defining my functionpublic int myreflect(string a, string b, string c, params int[] list)
Everything is working except that i need to somehow extract the arguements which are in the param array i.e., list. I need to capture those arguments and store them in another array..say int[] args..and use this args in Invokemember function, as parameters to invoke my M1 method. I hope I have done a fair job in explaining my problem. A little help would be greatly appreciated. Thanks in advance....Sonu
-
You could copy all the elements in the array: int[] args = new int[list.Length]; Array.Copy(list, args, list.Length); Or you could just copy the reference to the array: int[] args = list; Or why not just use the list array?
--- b { font-weight: normal; }
-
Thanx for the reply Guffa!! i tried using list directly, but its not working.. anyways i will try the other two ways you suggested... thanks once again....:-O
Sonu