13 | Request ID: @Model.RequestId
14 |
19 | Swapping to Development environment will display more detailed information about the error that occurred. 20 |
21 |22 | Development environment should not be enabled in deployed applications, as it can result in sensitive information from exceptions being displayed to end users. For local debugging, development environment can be enabled by setting the ASPNETCORE_ENVIRONMENT environment variable to Development, and restarting the application. 23 |
24 | -------------------------------------------------------------------------------- /src/DynamicExpresso.Core/Visitors/DisableReflectionVisitor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq.Expressions; 3 | using System.Reflection; 4 | using DynamicExpresso.Exceptions; 5 | 6 | namespace DynamicExpresso.Visitors 7 | { 8 | public class DisableReflectionVisitor : ExpressionVisitor 9 | { 10 | protected override Expression VisitMethodCall(MethodCallExpression node) 11 | { 12 | if (node.Object != null 13 | && (typeof(Type).IsAssignableFrom(node.Object.Type) 14 | || typeof(MemberInfo).IsAssignableFrom(node.Object.Type))) 15 | { 16 | throw new ReflectionNotAllowedException(); 17 | } 18 | 19 | return base.VisitMethodCall(node); 20 | } 21 | 22 | protected override Expression VisitMember(MemberExpression node) 23 | { 24 | if ((typeof(Type).IsAssignableFrom(node.Member.DeclaringType) 25 | || typeof(MemberInfo).IsAssignableFrom(node.Member.DeclaringType)) 26 | && node.Member.Name != "Name") 27 | { 28 | throw new ReflectionNotAllowedException(); 29 | } 30 | 31 | return base.VisitMember(node); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/DynamicExpresso.Core/Exceptions/AssignmentOperatorDisabledException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | using DynamicExpresso.Resources; 4 | 5 | namespace DynamicExpresso.Exceptions 6 | { 7 | [Serializable] 8 | public class AssignmentOperatorDisabledException : ParseException 9 | { 10 | public AssignmentOperatorDisabledException(string operatorString, int position) 11 | : base(string.Format(ErrorMessages.AssignmentOperatorNotAllowed, operatorString), position) 12 | { 13 | OperatorString = operatorString; 14 | } 15 | 16 | public string OperatorString { get; private set; } 17 | 18 | protected AssignmentOperatorDisabledException( 19 | SerializationInfo info, 20 | StreamingContext context) 21 | : base(info, context) 22 | { 23 | OperatorString = info.GetString("OperatorString"); 24 | } 25 | 26 | public override void GetObjectData(SerializationInfo info, StreamingContext context) 27 | { 28 | info.AddValue("OperatorString", OperatorString); 29 | 30 | base.GetObjectData(info, context); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /sample/DynamicExpressoWebShell/Controllers/InterpreterController.cs: -------------------------------------------------------------------------------- 1 | using DynamicExpressoWebShell.Services; 2 | using System.Text.Json; 3 | using System; 4 | using Microsoft.AspNetCore.Mvc; 5 | 6 | namespace DynamicExpressoWebShell.Controllers 7 | { 8 | public class InterpreterController : Controller 9 | { 10 | private readonly WebShell _webShell; 11 | 12 | public InterpreterController(WebShell webShell) 13 | { 14 | _webShell = webShell; 15 | } 16 | 17 | [HttpPost] 18 | public ActionResult Eval(string expression) 19 | { 20 | try 21 | { 22 | var result = _webShell.Eval(expression); 23 | 24 | //if (result == null) 25 | // return Json(new { success = true, result = "
27 | Dynamic Expresso is an expression interpreter for simple C# statements.
28 |
29 | Try it now directly in your browser.
30 |
Dynamic Expresso version: @assemblyVersion
38 | @*type "help" for help
*@ 39 | 40 |
45 | Dynamic Expresso understands a subset of C# syntax (numeric and string operators, comparison operators, typeof, new, primitive types, Math and Convert classes, ...).
46 | It supports single statement expression only. See documentation for more information.
47 | In this example all the results are serialized using json to be more human readable.
48 |
56 | Here some expressions that you can try: 57 |
58 |5 + 2 * 8 / (80 + 9.9)"Hello" + " " + "world!"DateTime.Now.AddDays(30)new DateTime(2020, 2, 13)string.Format("My name is {0}. Today is {1}", "R2-D2", DateTime.Now.ToShortDateString())Commands.CountCommands.Clear()Commands.GetLastCommands()
70 | The Commands variable is just for demostration purpose.
71 |
79 |
80 | shell javascript code is based on the mongulator project (https://github.com/banker/mongulator)
81 | Copyright (c) 2009 Kyle Banker
82 |
83 |
" + str + ""; 31 | } 32 | 33 | var BR = function () { 34 | return "