public void ExpressionSlimToExpressionConverter_Throw() { var ex = new Exception(); var conv = new ExpressionSlimToExpressionConverter(); { var t = ExpressionSlim.Throw(Expression.Constant(ex).ToExpressionSlim()); var e = conv.Visit(t); Assert.AreEqual(ExpressionType.Throw, e.NodeType); var u = (UnaryExpression)e; Assert.AreEqual(typeof(void), u.Type); Assert.AreEqual(ExpressionType.Constant, u.Operand.NodeType); var c = (ConstantExpression)u.Operand; Assert.AreSame(ex, c.Value); } { var t = ExpressionSlim.Throw(Expression.Constant(ex).ToExpressionSlim(), typeof(int).ToTypeSlim()); var e = conv.Visit(t); Assert.AreEqual(ExpressionType.Throw, e.NodeType); var u = (UnaryExpression)e; Assert.AreEqual(typeof(int), u.Type); Assert.AreEqual(ExpressionType.Constant, u.Operand.NodeType); var c = (ConstantExpression)u.Operand; Assert.AreSame(ex, c.Value); } { var t = ExpressionSlim.MakeUnary(ExpressionType.Throw, Expression.Constant(ex).ToExpressionSlim(), type: null); var e = conv.Visit(t); Assert.AreEqual(ExpressionType.Throw, e.NodeType); var u = (UnaryExpression)e; Assert.AreEqual(typeof(void), u.Type); Assert.AreEqual(ExpressionType.Constant, u.Operand.NodeType); var c = (ConstantExpression)u.Operand; Assert.AreSame(ex, c.Value); } }
#pragma warning restore IDE0060 // Remove unused parameter protected static Expression ExpressionRoundtrip(Expression e) { var exprToSlim = new ExpressionToExpressionSlimConverter(); var slimToExpr = new ExpressionSlimToExpressionConverter(); return(slimToExpr.Visit(exprToSlim.Visit(e))); }
private static void AssertRoundtrip(Expression e) { var toSlim = new ExpressionToExpressionSlimConverter(); var toLinq = new ExpressionSlimToExpressionConverter(); var eqComp = new ExpressionEqualityComparer(() => new Comparator()); var s = toSlim.Visit(e); var r = toLinq.Visit(s); Assert.IsTrue(eqComp.Equals(e, r), e.ToString()); }
public override Expression Reduce(ExpressionSlim expression) { return(_reducer.Visit(expression)); }