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

What is the best practice of using C # as an embedded internal scripting application for a .NET 3.5 application? I have an application with a few small IronRuby scripts. None of them use the dynamic nature of IronRuby.

Apparently IronRuby or IronPython will use it against our corporate standard right now. Ooopps. What is the best way to use C # as a scripting language?

The only thing I liked about IronRuby was that I could make small changes while the application was running, and then run the scripts again. Any way to do this in C #? Or do you have to constantly restart the application?

+4
source share
4 answers

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

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

Currently, you can fake it by creating a temporary โ€œcode fileโ€ as a line in memory, running the C # compiler from the outside to create a new assembly in memory, and then load and execute this assembly. This will work well once, but if you want to update it without rebooting, you will have to load the assembly in memory in a new application, and unload the old one each time (which becomes quite complicated).

Honestly, I would not bother. C # does not make a very good scripting language because of its compiled nature and static typing

+6
source

You may be able to update your C # code while the application is running, but it will not be easy. This topic discusses attempts to do such a thing:

http://www.eggheadcafe.com/software/aspnet/30778032/assemblyload-and-updat.aspx

At the bottom of this thread there is a link to this article that looks useful:

http://dotnet.sys-con.com/node/113340

The main approach is to load the plugin assembly into a separate AppDomain, and then unload the entire AppDomain if you want to replace your plugin.

+1
source

Embedding IronRuby for scripting is not too complicated.
Jimmy Schementi (one of IronRuby's developers) has a complete, detailed example of this:

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

I donโ€™t think it will be very easy to do with C #.

Sorry, I know this does not answer your question, but I hope it will be useful for those who are trying to deal with scripting through IronRuby.

+1
source

You can always try using CS Script.

http://www.csscript.net/

Personally, I would suggest sticking with either IronRuby or Lua for scripting.

+1
source

Source: https://habr.com/ru/post/1299346/


All Articles