public override object VisitAnonymousMethodExpression(AnonymousMethodExpression anonymousMethodExpression, object data) { base.VisitAnonymousMethodExpression(anonymousMethodExpression, data); LambdaExpression lambda = new LambdaExpression(); lambda.Parameters = anonymousMethodExpression.Parameters; if (anonymousMethodExpression.Body.Children.Count == 1) { ReturnStatement rs = anonymousMethodExpression.Body.Children[0] as ReturnStatement; if (rs != null) { lambda.ExpressionBody = rs.Expression; } else { lambda.StatementBody = anonymousMethodExpression.Body.Children[0] as Statement; lambda.ReturnType = new TypeReference("System.Void", true); } } else { var visitor = new ReturnStatementVisitor(); anonymousMethodExpression.AcceptVisitor(visitor, null); lambda.StatementBody = anonymousMethodExpression.Body; if (!visitor.HasReturn) { lambda.ReturnType = new TypeReference("System.Void", true); } } ReplaceCurrentNode(lambda); return(null); }