473,394 Members | 1,739 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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@
Nov 15 '05 #1
3 1009
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.
"matt" <ma*************@fox-net.co.uk> wrote in message
news:01****************************@phx.gbl...
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@

Nov 15 '05 #2
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" <ma*************@fox-net.co.uk> wrote in message
news:01****************************@phx.gbl...
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@

Nov 15 '05 #3
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

-----Original Message-----
Sure. Get the Type object (either using type(MyClass) or
<instance>.GetType()), and then call MethodInvoke(). Note that this isslower than calling normally. You can get some speed increase by creating adelegate of of a MethodInfo (use type.GetMethods to get the appropriatemethod 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" <ma*************@fox-net.co.uk> wrote in message
news:01****************************@phx.gbl...
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@

.

Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Allaigre David | last post by:
I'm trying to retreive some information from the querystring. The web site is as default configure in "utf-8". But on only one page i need to change dynamicly the contentEncoding to retreive...
2
by: Programmer | last post by:
Hi all How can I add a text object on an Crystal Report dynamicly??? I have an aspx page that loads the report but i cant find the methods to insert new Items on the rpt Can anyone help me...
2
by: FAN | last post by:
I want to define some function in python script dynamicly and call them later, but I get some problem. I have tried the following: ################################## # code...
2
by: Jelle van Baardewijk | last post by:
Can anyone tell me how to to create a control instance dynamicly. Example: When I have a string value with the value 'TextBox'. I want to create a TextBox instance. I know that i can do the...
4
by: Bill Sun | last post by:
Hi, All I have a conventional question, How to create a 3 dimension array by C language. I see some declare like this: int *** array; int value; array = create3Darray(m,n,l);
5
by: Henke | last post by:
Hi! I add some web user controls dynamicly with: myPanel.Controls.Add(Page.LoadControl("MyDynamiclyAddedPage.ascx")); the style of the controls on the user control is set from a css-class, by...
1
by: Henke | last post by:
Hi I have a aspx-page with a panel-control. On this panel control I add user controls dynamicly with LoadControl and panel.Controls.Add(myControl). On some of the dynamicly added user controls I...
2
by: Chris Monro | last post by:
Hi! I've created a UI control that adds(Creates) or subtracts(Destroys) standard buttons on a panel. I want to have each of these created buttons become accessible as UI elements, just as the...
1
by: kulak | last post by:
As my search for a solution to this problem gave no useful results, I decided to post it here. I appreciate any help in this regard. I'm having a minor, yet annoying, problem: When opening a...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.