Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. dynamic function call

dynamic function call

Scheduled Pinned Locked Moved C#
help
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vatzcar
    wrote on last edited by
    #1

    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

    G E 2 Replies Last reply
    0
    • V vatzcar

      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

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      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; }

      V 1 Reply Last reply
      0
      • V vatzcar

        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

        E Offline
        E Offline
        engsrini
        wrote on last edited by
        #3

        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

        V 1 Reply Last reply
        0
        • G Guffa

          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; }

          V Offline
          V Offline
          vatzcar
          wrote on last edited by
          #4

          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.

          G 1 Reply Last reply
          0
          • E engsrini

            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

            V Offline
            V Offline
            vatzcar
            wrote on last edited by
            #5

            i did, and finally nothing happens, not even any exception.

            1 Reply Last reply
            0
            • V vatzcar

              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.

              G Offline
              G Offline
              Guffa
              wrote on last edited by
              #6

              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; }

              V 1 Reply Last reply
              0
              • G Guffa

                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; }

                V Offline
                V Offline
                vatzcar
                wrote on last edited by
                #7

                thanks for your reply :) i've fixed the problem with the help of reflection :)

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups