Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        /// <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));
        }
Ejemplo n.º 3
0
        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));
        }
Ejemplo n.º 4
0
        /// <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));
        }