Hello
I am using the scriptRun component for evaluating expressions continuously at runtime every time a specific editor is open.
The evaluate method looks somethings like this
public object MyEvaluator(object instance, string expression)
{
scriptRun1.GlobalItems.Clear();
if (instance is MyTextModel item)
{
scriptRun1.GlobalItems.Add(new ScriptGlobalItem("item", item.GetType(), item));
}
else if (instance is MyOtherModel model)
{
//Force refresh here but is slow
//If globalitems already contained a MyOtherModel instance it will not compile
//because the previous compile also included a MyOtherModel instance
scriptRun1.GlobalItems.Add(new ScriptGlobalItem("model", model.GetType(), model));
forceRecompile = true;
}
scriptRun1.ScriptSource.FromExpression(expression);
if (!scriptRun1.Compiled || forceRecompile)
{
if (!scriptRun1.Compile())
{
//MessageBox.Show(string.Join(' ', scriptRun1.ScriptHost.CompilerErrors));
}
}
return scriptRun1.RunMethod("Evaluate");
}
As stated in the comments, i have to recompile the globalItem if an instance of the same type was already compiled before. It is required that the name “model” is persisted because there are multiple editors where i want to be able to type in “model” with intellisense. The instance should simply be swapped out. Is there a way to achieve this behaviour?