private static IfNode IsIfReturnExpr(AstNode node, out AstNode condition, ref AstNode matchExpression) { // set the condition to null initially condition = null; // must be an if-node with no false block, and a true block with one statement var ifNode = node as IfNode; if (ifNode != null && ifNode.FalseBlock == null && ifNode.TrueBlock != null && ifNode.TrueBlock.Count == 1) { // and that one statement needs to be a return statement var returnNode = ifNode.TrueBlock[0] as ReturnNode; if (returnNode != null) { if (matchExpression == null || matchExpression.IsEquivalentTo(returnNode.Operand)) { // either we don't care what the return expression is, // or we do care and it's a match. matchExpression = returnNode.Operand; condition = ifNode.Condition; } } } // but we will only return the if-node IF the matchedExpression and the // condition are both non-null (our TRUE state) return condition != null && matchExpression != null ? ifNode : null; }