[Mono-devel-list] Interactive C# prompt

Elliott Draper el at eldiablo.co.uk
Tue Jul 19 11:39:02 EDT 2005


Colin JN Breame wrote:

>Hello,
>
>I'm wondering whether there is such a thing as an interactive C# prompt for 
>mono. e.g. where commands can be entered and executed one-by-one.
>
>If not, any ideas about how I would go about writting something like this?
>_______________________________________________
>Mono-devel-list mailing list
>Mono-devel-list at lists.ximian.com
>http://lists.ximian.com/mailman/listinfo/mono-devel-list
>
>  
>
Hi,

Are you referring to a way to execute small C# code statements and have 
them executed as if they were within a simple program, on the fly? 
Because if so, then you can use the classes and methods within 
System.CodeDom, specifically within System.CodeDom.Compiler, to compile 
and execute code. So you can take a command such as 
"string.Compare("test","testing")" from a prompt, build it up into a 
simple class with an entry point, use an ICodeCompiler object (which one 
depends on which language) to compile the code, and then execute the 
assembly in memory, returning the result back to the prompt (without 
saving any of the code or binary assembly to file, truly on the fly). 
This leaves you with a basic eval prompt for running simple statements, 
in whatever .Net language you choose to support using different 
ICodeCompiler's. You could ofcourse get as complicated as you like in 
building up the program to execute, depending on how much information 
you want to let the user enter straight from the command line, from 
simple statements to full code blocks.

I have actually started working on a DotNet/Mono written shell named 
xSh, for both Windows and Linux, and one of the plugins I'm going to 
incorporate will be a simple C# code evaluator for running simple 
functions and simple bits of code off the command line. I hope to have a 
beta release out fairly soonish.

If this was what your after and you'd like more info, or a code sample, 
just let me know.

Oh and if I'm way off base and this isn't what you wanted... then ignore 
my ramblings :-)

Regards,
-= El =-



More information about the Mono-devel-list mailing list