dynamicly running methods.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • matt

    #1

    dynamicly running methods.

    can i say store a method name in a database & then bring
    it back & run it?

    sort of like using the eval() in javascript?

    i would prefer not to have a masively big switch
    statement & instead store the relevent method name in the
    database with the relevent record.

    thanks in advance for any help.

    M@
  • Eric Gunnerson [MS]

    #2
    Re: dynamicly running methods.

    Sure. Get the Type object (either using type(MyClass) or
    <instance>.GetT ype()), and then call MethodInvoke(). Note that this is
    slower than calling normally. You can get some speed increase by creating a
    delegate of of a MethodInfo (use type.GetMethods to get the appropriate
    method info), and then calling through that.

    --
    Eric Gunnerson

    Visit the C# product team at http://www.csharp.net
    Eric's blog is at http://blogs.gotdotnet.com/ericgu/

    This posting is provided "AS IS" with no warranties, and confers no rights.
    "matt" <matt_newsgroup s@fox-net.co.uk> wrote in message
    news:019b01c3b2 15$5bc35090$a50 1280a@phx.gbl.. .[color=blue]
    > can i say store a method name in a database & then bring
    > it back & run it?
    >
    > sort of like using the eval() in javascript?
    >
    > i would prefer not to have a masively big switch
    > statement & instead store the relevent method name in the
    > database with the relevent record.
    >
    > thanks in advance for any help.
    >
    > M@[/color]


    Comment

    • Chris R

      #3
      Re: dynamicly running methods.

      Check out
      Type.GetMethod
      method. This most likely does what you want to do. It takes a string, with
      an overloaded parameter list for other options.

      Chris R.

      "matt" <matt_newsgroup s@fox-net.co.uk> wrote in message
      news:019b01c3b2 15$5bc35090$a50 1280a@phx.gbl.. .[color=blue]
      > can i say store a method name in a database & then bring
      > it back & run it?
      >
      > sort of like using the eval() in javascript?
      >
      > i would prefer not to have a masively big switch
      > statement & instead store the relevent method name in the
      > database with the relevent record.
      >
      > thanks in advance for any help.
      >
      > M@[/color]


      Comment

      • matt \(ziba\)

        #4
        Re: dynamicly running methods.

        thank you both, first time posting in a news group kinda
        feel part of this whole programming world now.. :)

        keep up the good work & i'm sure i'll be back maybe even
        answer some questions myself, once i've ported myself
        fully over to c#...

        i'll try your suggestions tommorow. :)

        Regards
        Matt
        England, UK

        [color=blue]
        >-----Original Message-----
        >Sure. Get the Type object (either using type(MyClass) or
        ><instance>.Get Type()), and then call MethodInvoke().[/color]
        Note that this is[color=blue]
        >slower than calling normally. You can get some speed[/color]
        increase by creating a[color=blue]
        >delegate of of a MethodInfo (use type.GetMethods to get[/color]
        the appropriate[color=blue]
        >method info), and then calling through that.
        >
        >--
        >Eric Gunnerson
        >
        >Visit the C# product team at http://www.csharp.net
        >Eric's blog is at http://blogs.gotdotnet.com/ericgu/
        >
        >This posting is provided "AS IS" with no warranties, and[/color]
        confers no rights.[color=blue]
        >"matt" <matt_newsgroup s@fox-net.co.uk> wrote in message
        >news:019b01c3b 215$5bc35090$a5 01280a@phx.gbl. ..[color=green]
        >> can i say store a method name in a database & then[/color][/color]
        bring[color=blue][color=green]
        >> it back & run it?
        >>
        >> sort of like using the eval() in javascript?
        >>
        >> i would prefer not to have a masively big switch
        >> statement & instead store the relevent method name in[/color][/color]
        the[color=blue][color=green]
        >> database with the relevent record.
        >>
        >> thanks in advance for any help.
        >>
        >> M@[/color]
        >
        >
        >.
        >[/color]

        Comment

        Working...