CS-Script makes adding classes and objects to the current process space really easy. Can something like this be done with ScriptRun? The key is getting a reference to the created object back from the script.
string Code = @"
public class TriggerPine : ITrigger
{
public bool Test(Organization Organization, ActionTrigger Action)
{
return true;
}
}
";
This can be done in a similar way. Here’s a code snippet:
Kind regards,
Dmitry
namespace WinFormsApp1;
{
public enum Organization
{
None,
}
public enum ActionTrigger
{
None,
}
public interface ITrigger
{
bool Test(Organization Organization, ActionTrigger Action);
}
}
private void Test()
{
string Code = @"
// namespace where ITrigger is defined
using WinFormsApp1;
public class TriggerPine : ITrigger
{
public bool Test(Organization Organization, ActionTrigger Action)
{
return true;
}
}
// To return object from script.
public class Program
{
public static ITrigger NewTrigger()
{
return new TriggerPine();
}
}
";
var scriptRun = new ScriptRun();
scriptRun.ScriptLanguage = ScriptLanguage.CSharp;
scriptRun.AssemblyKind = ScriptAssemblyKind.DynamicLibrary;
scriptRun.ScriptSource.FromScriptCode(Code).WithDefaultReferences().References.Add(Assembly.GetExecutingAssembly().Location);
var trigger = scriptRun.RunMethod("NewTrigger") as ITrigger;
bool IsTest = trigger.Test(Organization.None, ActionTrigger.None);
}