public static object EvaluateCode(this ScriptContext context, string code, Dictionary <string, object> args = null) { var pageResult = GetCodePageResult(context, code, args); if (!pageResult.EvaluateResult(out var returnValue)) { throw new NotSupportedException(ScriptContextUtils.ErrorNoReturn); } return(ScriptLanguage.UnwrapValue(returnValue)); }
/// <summary> /// Evaluate #Script and return value /// </summary> public static object Evaluate(this ScriptContext context, string script, Dictionary <string, object> args = null) { var pageResult = new PageResult(context.SharpScriptPage(script)); args.Each((x, y) => pageResult.Args[x] = y); if (!pageResult.EvaluateResult(out var returnValue)) { throw new NotSupportedException(ScriptContextUtils.ErrorNoReturn); } return(ScriptLanguage.UnwrapValue(returnValue)); }
public static async Task <object> EvaluateCodeAsync(this ScriptContext context, string code, Dictionary <string, object> args = null) { var pageResult = GetCodePageResult(context, code, args); var ret = await pageResult.EvaluateResultAsync(); if (!ret.Item1) { throw new NotSupportedException(ScriptContextUtils.ErrorNoReturn); } return(ScriptLanguage.UnwrapValue(ret.Item2)); }
/// <summary> /// Evaluate #Script and convert returned value to T asynchronously /// </summary> public static async Task <object> EvaluateAsync(this ScriptContext context, string script, Dictionary <string, object> args = null) { var pageResult = new PageResult(context.SharpScriptPage(script)); args.Each((x, y) => pageResult.Args[x] = y); var ret = await pageResult.EvaluateResultAsync(); if (!ret.Item1) { throw new NotSupportedException(ScriptContextUtils.ErrorNoReturn); } return(ScriptLanguage.UnwrapValue(ret.Item2)); }