0

I'm analysing if it is possible to control my application with scripts/macros.

My application is a WPF application written in c#/VS2015 and I'm trying to do the following (pseudo code)

public interface IExposedTasks
{
    IEnumerable<Customer> Customers {get; }
    void ShowSum(int sum);
}

public static class Host : IExposedTasks 
{
    public IEnumerable<string> Customers { ... }

    public void ShowSum(int sum)
    {
        MessageBox.Show("Sum: " + sum.ToString());
    }
}

...

public void ExecuteScript(string script)
{
    // execute script 
}

The script should be able to access all data from IExposedTasks and do something like:

var sum = 0;

foreach(var customer in Host.Customers) 
{
    sum += customer.Value;
}

Host.ShowSum(sum);

The language of the scripts could be in c#, JavaScript or VB.

I have tried to do this with Cs-Script, but it does not seem to work on Win10/VS2015.

COM is not an alternative.

Can anyone point me into the right direction?

Thanks in advance!

Markus Safar
  • 6,324
  • 5
  • 28
  • 44
Mikael
  • 71
  • 1
  • 6
  • What an internal application of us does is simply accepting arbitrary C#-Code, compiling it on the fly – Christian Sauer Jan 30 '16 at 12:08
  • Right direction: Roslyn: http://www.jayway.com/2015/05/09/using-roslyn-to-build-a-simple-c-interactive-script-engine/ – SynerCoder Jan 30 '16 at 12:10
  • @SynerCoder: Thanks, I have read and tested a bit of Roslyn, and there are some samples available on the Internet which describes what I'm looking for, http://stackoverflow.com/questions/24733556/pass-object-instance-to-roslyn-scriptengine, for example. Unfortunately these examples seems outdated since they are using "other objects" like Session which no longer seems to be supported, so this is not working as it seems. – Mikael Jan 30 '16 at 17:06

0 Answers0