alielie
2026-09-10 f3889f2d36c50cf99468594854def9b7ed069fb5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using DynamicExpressoWebShell.Services;
using System.Text.Json;
using System;
using Microsoft.AspNetCore.Mvc;
 
namespace DynamicExpressoWebShell.Controllers
{
    public class InterpreterController : Controller
    {
        private readonly WebShell _webShell;
 
        public InterpreterController(WebShell webShell)
        {
            _webShell = webShell;
        }
 
        [HttpPost]
        public ActionResult Eval(string expression)
        {
            try
            {
                var result = _webShell.Eval(expression);
 
                //if (result == null)
                //    return Json(new { success = true, result = "<null>" });
 
                var options = new JsonSerializerOptions { WriteIndented = true };
                var prettifyOutput = JsonSerializer.Serialize(result, options);
 
                return Json(new { success = true, result = prettifyOutput });
            }
            catch (Exception ex)
            {
                return Json(new { success = false, result = ex.Message });
            }
        }
 
    }
}