예제 #1
0
        public static CodeThrowExceptionStatement @throw(Expression <Action> exp)
        {
            VisitorContext ctx = new VisitorContext();

            ctx.VisitParams(exp.Parameters);
            NewExpression newExp = new QueryVisitor((e) => e is NewExpression).Visit(exp) as NewExpression;

            return(new CodeThrowExceptionStatement(new CodeObjectCreateExpression(
                                                       new CodeTypeReference(newExp.Type),
                                                       new CodeExpressionVisitor(ctx).VisitExpressionList(newExp.Arguments).ToArray()
                                                       )));
        }