Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0 scripting
I need a script engine for a C# app but can’t figure out what is the best choice. I have looked around the net and found a number of possible candidates, but I think I need some advice from someone with practical experience in C# scripting. I am looking for something that is fairly easy to integrate into the C# app, yet is powerful enough to satisfy my requirements:
 
The scripting language should be C#.

The app has a number of user definable “business rules “, each having a condition that determines when and how the rules apply. This condition is the C# script.

There will also be C# scripts in the form of “library code files” where the user can define common functions that can be used in the rule conditions. Business rules and library code files are stored in a database.

It should be possible to expose objects (methods, fields and properties) in the main app to the scripting engine so that the scripts can use functionality in the app and communicate with it.
 
Once loaded, the rules are evaluated frequently, so the evaluation of the scripts should be fast. Best is probably if script code is compiled once and then executed from a cache until the script is changed.
 
There should preferably be some support for debugging the scripts.
 
I also need an embeddable C# editor with syntax highlighting, code completion and intelli sense. Like in Visual Studio. I need some advice from someone with practical experience also on this choice, so I don’t step into some nasty hole and have to spend countless hours struggling with some buggy add-on.
 
Thanks!
Posted 25-Sep-12 2:49am
jmh1309

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Since .net has a CodeDOM compiler it is very easy to work with and compile code snippets at runtime.
 
The only real issue is your application architecture must support some kind of plug-in or interface for such a feature.
public class pluginXYZ : IMyAppPlugin
{
     public object Run(IMyAPI api, object[] args)
     {
        // your code here
     }
}
So from the sample above you can see you have created a IMyAppPlugin which your snippets must implement and the IMyAPI is an interface to your internal functionality say (Query(), LogMessage() etc.)
 
There are a lot of commercial and open source syntax highlighting and intellisense editors also which you can use:
Fast Colored TextBox for Syntax Highlighting[^]
http://www.icsharpcode.net/OpenSource/SD/[^]
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 613
1 BillWoodruff 299
2 PIEBALDconsult 290
3 George Jonsson 265
4 Sergey Alexandrovich Kryukov 254
0 Sergey Alexandrovich Kryukov 10,694
1 OriginalGriff 5,354
2 Maciej Los 5,354
3 CPallini 3,729
4 BillWoodruff 3,556


Advertise | Privacy | Mobile
Web04 | 2.8.141029.1 | Last Updated 4 Dec 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100