dynamicly running methods.

  • Thread starter Thread starter matt
  • Start date Start date
M

matt

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@
 
Sure. Get the Type object (either using type(MyClass) or
<instance>.GetType()), 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.
 
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.
 
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
 
Back
Top