How do I add server -side code at runtime?

B

bestwerx

I am building an application that is totally data driven. The pages are
built from scratch at runtime.I have everything working fine. Now all I
need to do is to have the ability to add code both server-side and
client-sie at runtime. I think I have pretttty much figured out the
client side part. My problem is the servre-side code. How do i inject
and/or run server-side code (frfom the database) at runtime?
 
D

dave.dolan

Don't forget about DynamicMethod. You can create a delegate to an arbitrary
method, constructor, or property accessor anywhere... and it works lots
faster than the Invoke on MethodInfo via reflection. (You can cache
delegates in a dictionary, for example, and have the ability to access
properties or methods by a string name)

There is an introduction to this type of thing on a CodeProject article:
http://www.codeproject.com/csharp/DynamicMethodDelegates.asp?print=true

There's also something on MSDN about it, but it's not very helpful.

If you want to get really fancy and use generics that determine their type
parameters at runtime, then you'll have to do something like this :
http://musingmarc.blogspot.com/2006/08/how-to-do-late-dynamic-method-creation.html (Marc is one of my newfound hero's)
 
M

MRe

I found http://www.west-wind.com/presentations/dynamicCode/DynamicCode.htm
to be a pretty good reference on doing this.. put me right off the idea :)
You could also use the Script control (though you'll have to use vbscript or
javascript) - Add a reference to the COM \ Microsoft Script Control 1.0 and
do like..

<snip>
ScriptControl script = new ScriptControl();
script.Language = "vbscript";
script.AddObject("joe", new ken(), true);
Response.Write(script.Eval("(1 + 3) * joe.bob"));
</snip>

[ComVisible(true)]
public partial class ken
{
public int bob = 3;
}

...too easy!

Regards,
Eliott


| Thx
| I will try this
| And yes, I am generating code on the fly
| sw
|
| Gaurav Vaish (www.EduJini.IN) wrote:
| > Are you generating C#/VB.Net code on the fly?
| > Yikes! Well... you would be needing
| > System.CodeDom.Compiler.CSharpCodeProvider or
| > System.CodeDom.Compiler.VBCodeProvider
| >
| > for the code to be compiled on the fly.
| >
| > But I am damn sure... there are better things around. May be you can
share
| > some more information about your website / application!
| >
| >
| > --
| > Happy Hacking,
| > Gaurav Vaish | http://www.mastergaurav.org
| > http://www.edujini.in | http://webservices.edujini.in
| > -------------------
| >
| >
| > | > >I am building an application that is totally data driven. The pages are
| > > built from scratch at runtime.I have everything working fine. Now all
I
| > > need to do is to have the ability to add code both server-side and
| > > client-sie at runtime. I think I have pretttty much figured out the
| > > client side part. My problem is the servre-side code. How do i inject
| > > and/or run server-side code (frfom the database) at runtime?
| > >
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,268
Messages
2,571,094
Members
48,773
Latest member
Kaybee

Latest Threads

Top