using Elsa.Expressions.Models;
using Elsa.Mediator.Contracts;
using Microsoft.CodeAnalysis.Scripting;
namespace Elsa.CSharp.Notifications;
///
/// This notification is published every time a C# expression is about to be evaluated.
/// It gives subscribers a chance to configure the with additional functions and variables.
///
public record EvaluatingCSharp(ExpressionEvaluatorOptions Options, Script Script, ScriptOptions ScriptOptions, ExpressionExecutionContext Context) : INotification
{
///
/// Configures the with additional functions and variables.
///
public EvaluatingCSharp ConfigureScriptOptions(Func scriptOptions)
{
ScriptOptions = scriptOptions(ScriptOptions);
return this;
}
///
/// Appends the specified script to the current script.
///
public EvaluatingCSharp AppendScript(string script)
{
Script = Script.ContinueWith(script, ScriptOptions);
return this;
}
///
/// The that will be used to evaluate the expression.
///
public ScriptOptions ScriptOptions { get; set; } = ScriptOptions;
///
/// The that will be used to evaluate the expression.
///
public Script Script { get; set; } = Script;
}