scriplet kinds in .NET?

  • Thread starter Thread starter Alexander Cherny
  • Start date Start date
A

Alexander Cherny

Hi all!

Before .NET appears I used scriptlets to perform some functionality "on
fly". My application took the body of the scriptlet from a database (it
could be formed by some SELECT to perform some specific task), then saved it
as a file, put necessary parameters in the registry (to register it like
regsvr32 does) and ran it as a regular COM object. Then the application
cleaned everything up: unregistered the sriptlet (deleting any changes in
the registry made for it) and deleted the scriptlet file.

Maybe it's not a high-end way to get such a behaviour, but it worked. My
question is: is there any way like that to be realized "with a little help
from" .NET?

Thank you.
 
yes, maybe.

I know of a couple of options .
One is to utilize the eval() function that is built-in to JScript.NET.
What you can do is author your scriptlet code in JScript, then pass it to
the eval() function, and grab the result. You probably would do this
through a wrapper class - you cannot call jscript's eval() directly from C#,
but code that you write in JScript .NET is of course callable from VB.NET or
C# or .etc.... So write the wrapper class in JScript.NET. Within that
class you would call "Eval()". Invoke that class from VB or C# or whatever
you like.

2nd way:
use CodeDom.Compiler to compile code on the fly and invoke it via
reflection. This is a little more complex, but richer in possibilities.
You wouldn't need a complete app, just a Class (a type) and a method to
invoke. Google for InvokeMember() and you'll see the examples.

Another options
Someone wrote the beginning of a C# interpreter. Source code is available.
You could start there and maybe get where you need to be. Disclaimer: I
don't know anything about the code or any license it may have been released
under.
http://www.devhood.com/tools/tool_details.aspx?tool_id=641

-Dino
 
Back
Top