Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# instead of IronRuby as an embedded "scripting" language in .NET 3.5

What is the best practice for using C# as an embedded internal scripting application for a .NET 3.5 application? I have an app with a few small IronRuby scripts in it. None of which is really exploiting the dynamic nature of IronRuby.

Apparently its against our corporate standard to be using IronRuby or IronPython right now. Ooopps. What is the best way that I can use C# as my scripting language instead?

The one thing that I liked about IronRuby was I could make small changes while the app was running and then re-run the scripts. Any way to do this in C#? Or will have to constantly restart the app?

like image 231
BuddyJoe Avatar asked Jan 23 '23 16:01

BuddyJoe


2 Answers

At the moment you can't use C# as a scripting language, unless you switch to Mono.

Microsoft have stated that this (or similar functionality) is on the roadmap for C# version 5, which is far into the future.

You can currently fake it however, by creating a temporary "code file" as an in memory string, externally running the C# compiler to produce a new in-memory assembly, and then loading and executing that assembly.
This will work well once, but if you want to update it without restarting you'll have to load the in-memory assembly in a new appdomain, and unload the old one each time (which gets quite tricky).

To be honest, I wouldn't bother. C# doesn't make for a very good scripting language due to it's compiled nature and static typing

like image 73
Orion Edwards Avatar answered Jan 27 '23 13:01

Orion Edwards


Embedding IronRuby for scripting isn't too hard.
Jimmy Schementi (one of the IronRuby devs) has a complete, detailed example of this here:

http://blog.jimmy.schementi.com/2009/12/ironruby-rubyconf-2009-part-35.html

I don't think this will be very easy to do with C#.

Sorry, I know this doesn't answer your question but hopefully it will be of some use for those trying to deal w/ scripting through IronRuby.

like image 42
Kevin Radcliffe Avatar answered Jan 27 '23 12:01

Kevin Radcliffe