问题描述:

How could I approach this and are there any libraries out there to simplify it?

Users need to be able to write “Macros” in a VB like language which is stored in a plain text file.

These Macros are then attached to a given button in a C# App and executed when the button is clicked.

This is to be a windows forms app (could be WPF) using .net 4

I need to support popping up forms with controls on them such as text boxes, dropdown lists, labels, buttons & possibly a picture boxes too.

Basic functions like IF THEN ELSE, *, -, %, +, /, =, contains, yes no cancel message boxes…

Passing data from one script to another and getting any data returned.

I know what you are thinking tell them to install VB.net free edition! But I can’t as I need to add some bespoke functionality to extend the language also that allows communication with an in house system providing read and write to and from the system via existing COM objects.

Also the hosting c# app needs to contain many buttons each with the own script attached.

If this wasn’t bad enough the uses need to be able to write their own scripts so ideally some form of basic IDE is needed also.

Any suggestion?

网友答案:

Various technologies come to my mind which allow to implement parts of your requirements.

1.) Use Lightswitch for RAD forms
If you want to have a simple tool for rapidly building simple UIs you could use Lightswitch. You could provide your own assemblies added as references in Lightswitch that act as a code Framework for the LightSwitch Application.

2.) Windows Workflow Foundation RuleEngine
The RuleEngine allows you to modify/store businessrules. You can bind your internal assembly to the RuleEngine and then you have the possbility to script code based on the bound assembly.
The rules are simple "If" "then" "else" statements. http://karlreinsch.com/2010/10/18/wf-rules-unleashing-the-rule-engine-within-dot-net/

3.) Load XAML dynamically
With WPF you can serialize/deserialize UIs and load them from an file during runtime. With Blend or own tools you are able to create UIs and bind them to your business logic. See http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a53ff197-8703-4c6c-8726-45570304fb7b/

网友答案:

In the case your describing, I would suggest looking into already existing scripting techniques (perhaps such as LUA). You can then hook this sort of script up to existing code (such as an API you have built to leverage the functionality you desire).

The reason I suggest using an existing scripting system is because it has already been tried and tested, and it means you don't have to define a new language yourself and build the parsing engine.

相关阅读:
Top