Click here to Skip to main content
13,287,315 members (49,621 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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.

Posted 25-Sep-12 3:49am

1 solution

Rate this: bad
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[^][^]

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.171207.1 | Last Updated 4 Dec 2013
Copyright © CodeProject, 1999-2017
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