Пример #1
0
        private static bool WouldCauseDefiniteAssignmentErrors(
            SemanticModel semanticModel,
            LocalDeclarationStatementSyntax localStatement,
            BlockSyntax enclosingBlock,
            ILocalSymbol outLocalSymbol)
        {
            // See if we have something like:
            //
            //      int i = 0;
            //      if (Goo() || Bar(out i))
            //      {
            //          Console.WriteLine(i);
            //      }
            //
            // In this case, inlining the 'i' would cause it to longer be definitely
            // assigned in the WriteLine invocation.
            var nextStatement = localStatement.GetNextStatement();

            Contract.ThrowIfNull(nextStatement);

            var dataFlow = semanticModel.AnalyzeDataFlow(
                nextStatement,
                enclosingBlock.Statements.Last());

            Contract.ThrowIfNull(dataFlow);
            return(dataFlow.DataFlowsIn.Contains(outLocalSymbol));
        }