예제 #1
0
파일: Worse.cs 프로젝트: gredman/worse
        public static void Assert(Expression<Func<bool>> predicate)
        {
            Visitor visitor = new Visitor();
            Expression<Func<bool>> wrappedExpr = (Expression<Func<bool>>)visitor.Visit(predicate);
            Func<bool> wrappedFunc = wrappedExpr.Compile();

            if (!wrappedFunc())
                throw ExceptionFactory.Make(visitor.Captures);
        }
예제 #2
0
파일: Visitor.cs 프로젝트: gredman/worse
        protected override Expression VisitBinary(BinaryExpression node)
        {
            Expression left = node.Left;
            Expression right = node.Right;

            Visitor leftVisitor = new Visitor();
            Visitor rightVisitor = new Visitor();

            BinaryExpression binaryExpression = Expression.MakeBinary(node.NodeType, leftVisitor.Visit(left), rightVisitor.Visit(right));

            _captureNode.AddChild(leftVisitor.CaptureNode);
            _captureNode.AddChild(rightVisitor.CaptureNode);

            return WrapWithCapture(binaryExpression, node);
        }
예제 #3
0
파일: Visitor.cs 프로젝트: gredman/worse
        protected override Expression VisitMethodCall(MethodCallExpression node)
        {
            Expression instance = node.Object;

            Visitor instanceVisitor = new Visitor();
            List<Visitor> argumentVisitors = node.Arguments.Select(_ => new Visitor()).ToList();
            Expression[] argumentExpressions = argumentVisitors.Zip(node.Arguments, (v, a) => v.Visit(a)).ToArray();

            MethodCallExpression callExpression = node.Object == null
                // static
                ? Expression.Call(node.Method, argumentExpressions)
                // instance
                : Expression.Call(instanceVisitor.Visit(instance), node.Method, argumentExpressions);

            if (node.Object != null)
                _captureNode.AddChild(instanceVisitor.CaptureNode);
            foreach (Visitor visitor in argumentVisitors)
                _captureNode.AddChild(visitor.CaptureNode);

            return WrapWithCapture(callExpression, node);
        }
예제 #4
0
파일: Visitor.cs 프로젝트: gredman/worse
        protected override Expression VisitUnary(UnaryExpression node)
        {
            Expression operand = node.Operand;
            Visitor visitor = new Visitor();
            UnaryExpression unaryExpression = Expression.MakeUnary(node.NodeType, visitor.Visit(operand), operand.Type);

            _captureNode.AddChild(visitor.CaptureNode);
            return WrapWithCapture(unaryExpression, node);
        }