0

Say I have an application that is connected to a database, with its own forms that present data and allow data to be changed & entered, how would one extend the program to be extensible by a third party?

For example a third party would be able to write scripts that the user can run that would prompt the user for input. Part of the script would then take what the user inputed (integer/string/boolean) and do some basic programmatic things to it, math on integer values, concatenation on string values (and other string functions), and logical tests to trigger further user prompts etc etc, the scripting environment would also support reading/writing to the application's database.

Would this be done simply by having text files the program could run, with each line corresponding to a certain command? Then the application would read each line, figure out what command the line represents, and equate that to C# code? Are there any already existing solutions to this problem?

danbroooks
  • 2,712
  • 5
  • 21
  • 43
  • It kind of entirely depends on how in-depth you want things to be; however, it sounds like you want a simple "plugin system": http://stackoverflow.com/questions/1070787/writing-c-sharp-plugin-system – newfurniturey Aug 11 '13 at 14:08
  • Which language do you think would be appropriate for your application's users? C#? Javascript? Anything else? – citykid Aug 11 '13 at 14:27

2 Answers2

2

The question is fairly open, here some proven great extension tools:

Compiled Plugins written in C# would use Managed Extensibility Framework (MEF), a great and well designed extensibility option.

Scripted Extensions in C# might be possible soon when Roselyn is ready.

Scripting could also be accomplished by integrating Jurassic into your application.

citykid
  • 9,916
  • 10
  • 55
  • 91
2

There are several good choices if you want to embed a scripting language into a c# app. IronPython, IronScheme and IronRuby alL support the Dynamic Language Runtime so they can access objects from the host code. There's also Boo, which is a strongly typed CLR language that looks a lot like Python but can be easily embedded in a C# application and, like to the others, can interact with the host application. In general the embedding process is pretty simple - Michael Foord's IronPython site has a good example.

There's also NLua which is supposed to be a CLR friendly lua wrapper, but I have no personal knowledge of that one.

Out of all of the above, I'd expect the main thing driving your choice will be the preferences of the user base. Especially for the lightweight application you've described all of these choices should be well suited. If you wanted users to be able to do extensive programming on their own it's more complex, since the CLR ports of these languages dont usually support the same binary extensions as their C-based counterparts - for example, IronPython can't use the regular Perforce API module because it is built on a C-based binary extension module. All Iron* languages can use the same base class library as C#, though - you can import System.Windows.Forms into any of them to create GUI and so on.

theodox
  • 12,028
  • 3
  • 23
  • 36