private static bool IsReturned(MethodDeclarationSyntax method, StatementSyntax statement, SemanticModel semanticModel, ILocalSymbol identitySymbol)
        {
            var anonymousFunction = statement.FirstAncestorOfKind(SyntaxKind.ParenthesizedLambdaExpression,
                                                                  SyntaxKind.SimpleLambdaExpression, SyntaxKind.AnonymousMethodExpression) as AnonymousFunctionExpressionSyntax;
            IMethodSymbol methodSymbol;
            BlockSyntax   body;

            if (anonymousFunction != null)
            {
                methodSymbol = semanticModel.GetSymbolInfo(anonymousFunction).Symbol as IMethodSymbol;
                body         = anonymousFunction.Body as BlockSyntax;
            }
            else
            {
                methodSymbol = semanticModel.GetDeclaredSymbol(method);
                body         = method.Body;
            }
            if (body == null)
            {
                return(true);
            }
            var returnTypeSymbol = methodSymbol?.ReturnType;

            if (returnTypeSymbol == null)
            {
                return(false);
            }
            if (returnTypeSymbol.SpecialType == SpecialType.System_Void)
            {
                return(false);
            }
            var bodyDescendantNodes = body.DescendantNodes().ToList();
            var returnExpressions   = bodyDescendantNodes.OfType <ReturnStatementSyntax>().Select(r => r.Expression).Union(
                bodyDescendantNodes.OfKind <YieldStatementSyntax>(SyntaxKind.YieldReturnStatement).Select(yr => yr.Expression));
            var isReturning = returnExpressions.Any(returnExpression =>
            {
                var returnSymbol = semanticModel.GetSymbolInfo(returnExpression).Symbol;
                if (returnSymbol == null)
                {
                    return(false);
                }
                return(returnSymbol.Equals(identitySymbol));
            });

            return(isReturning);
        }
 private static bool IsReturned(MethodDeclarationSyntax method, StatementSyntax statement, SemanticModel semanticModel, ILocalSymbol identitySymbol)
 {
     var anonymousFunction = statement.FirstAncestorOfKind(SyntaxKind.ParenthesizedLambdaExpression,
         SyntaxKind.SimpleLambdaExpression, SyntaxKind.AnonymousMethodExpression) as AnonymousFunctionExpressionSyntax;
     IMethodSymbol methodSymbol;
     BlockSyntax body;
     if (anonymousFunction != null)
     {
         methodSymbol = semanticModel.GetSymbolInfo(anonymousFunction).Symbol as IMethodSymbol;
         body = anonymousFunction.Body as BlockSyntax;
     }
     else
     {
         methodSymbol = semanticModel.GetDeclaredSymbol(method);
         body = method.Body;
     }
     if (body == null) return true;
     var returnExpressions = body.DescendantNodes().OfType<ReturnStatementSyntax>().Select(r => r.Expression);
     var returnTypeSymbol = methodSymbol?.ReturnType;
     if (returnTypeSymbol == null) return false;
     if (returnTypeSymbol.SpecialType == SpecialType.System_Void) return false;
     var isReturning = returnExpressions.Any(returnExpression =>
     {
         var returnSymbol = semanticModel.GetSymbolInfo(returnExpression).Symbol;
         if (returnSymbol == null) return false;
         return returnSymbol.Equals(identitySymbol);
     });
     return isReturning;
 }