dynamic function call
-
i want to call a function dynamically which will differ according to my need. thing i need something like this:
private void FUNCTION_NAME(string ANY_STRING) { string ANOTHER_STRING="func"+ANY_STRING; ANOTHER_STRING.ANY_STRING(); }
i'll get ANY_STRING from some other source and that's the name which will refer the class name and part of function name too. any help will be great :) -- modified at 11:50 Friday 17th March, 2006 -
i want to call a function dynamically which will differ according to my need. thing i need something like this:
private void FUNCTION_NAME(string ANY_STRING) { string ANOTHER_STRING="func"+ANY_STRING; ANOTHER_STRING.ANY_STRING(); }
i'll get ANY_STRING from some other source and that's the name which will refer the class name and part of function name too. any help will be great :) -- modified at 11:50 Friday 17th March, 2006 -
i want to call a function dynamically which will differ according to my need. thing i need something like this:
private void FUNCTION_NAME(string ANY_STRING) { string ANOTHER_STRING="func"+ANY_STRING; ANOTHER_STRING.ANY_STRING(); }
i'll get ANY_STRING from some other source and that's the name which will refer the class name and part of function name too. any help will be great :) -- modified at 11:50 Friday 17th March, 2006Yes it is possible but i thing U need to create atleast atleast one Object for the class name that ur specifying in the string and u can use Type t=typeof(ClassName) t.InvokeMember("FunctionName", BindingFlags, null, obj, new FunctionArgsobj[]); Hope it will help Regards, Thanks and Regards, Srini
-
It's possible to do that using reflection, but I doubt that you really need that. Why don't you explain what you are trying to accomplish, instead of asking how to do it the way that you think it's done? --- b { font-weight: normal; }
Guffa wrote:
It's possible to do that using reflection, but I doubt that you really need that. Why don't you explain what you are trying to accomplish, instead of asking how to do it the way that you think it's done?
well.. i'm trying to do is, i have one xml file which maintains which modules user has choosen to use. then my app. will load those module detail in menu(this far i've completed). when user clicks one menu that particular module's entry function will be called. now menu click event passing me the 'SENDER', from which i can extract the menu name which i've to use as identifier(nothing else i've got better than this after having many suggestion from people). after clicking the menu i'll run the entry function of that particular module. the important thing is, one user may have choosen completely different modules than other.
-
Yes it is possible but i thing U need to create atleast atleast one Object for the class name that ur specifying in the string and u can use Type t=typeof(ClassName) t.InvokeMember("FunctionName", BindingFlags, null, obj, new FunctionArgsobj[]); Hope it will help Regards, Thanks and Regards, Srini
-
Guffa wrote:
It's possible to do that using reflection, but I doubt that you really need that. Why don't you explain what you are trying to accomplish, instead of asking how to do it the way that you think it's done?
well.. i'm trying to do is, i have one xml file which maintains which modules user has choosen to use. then my app. will load those module detail in menu(this far i've completed). when user clicks one menu that particular module's entry function will be called. now menu click event passing me the 'SENDER', from which i can extract the menu name which i've to use as identifier(nothing else i've got better than this after having many suggestion from people). after clicking the menu i'll run the entry function of that particular module. the important thing is, one user may have choosen completely different modules than other.
Make a base class or an interface for the modules, so that you can call the method without caring which of the modules it is. To get the right module you can do a lookup-table, like putting references to the modules in a hash-table. --- b { font-weight: normal; }
-
Make a base class or an interface for the modules, so that you can call the method without caring which of the modules it is. To get the right module you can do a lookup-table, like putting references to the modules in a hash-table. --- b { font-weight: normal; }