public override Expression Visit(Expression node) { // Looking through allowed expression types. if (AllowedExpressionTypes.Contains(node.NodeType)) { return(base.Visit(node)); } throw new Exception($"Unsupported expression type: '{node.NodeType}'"); }
protected override Expression VisitBinary(BinaryExpression node) { // Looking through allowed operation types. if (!AllowedExpressionTypes.Contains(node.NodeType)) { throw new Exception($"Unsupported operation: '{node.NodeType}'"); } // Visiting both right and left part of a binary expression, then invoking arithmetic operation with constants. var result = Expression.Lambda(node.Update(Visit(node.Left), node.Conversion, Visit(node.Right))).Compile().DynamicInvoke(); return(Expression.Constant(result, typeof(int))); }