public override void VisitTry(ITryOperation operation)
            {
                Visit(operation.Body);
                foreach (var catchClause in operation.Catches)
                {
                    Visit(catchClause);
                }

                _finallyBlockNestingDepth++;
                Visit(operation.Finally);
                _finallyBlockNestingDepth--;
            }
Exemplo n.º 2
0
        public override void VisitTry(ITryOperation operation)
        {
            Assert.Equal(OperationKind.Try, operation.Kind);
            IEnumerable <IOperation> children = new[] { operation.Body };

            children = children.Concat(operation.Catches);
            if (operation.Finally != null)
            {
                children = children.Concat(new[] { operation.Finally });
            }

            AssertEx.Equal(children, operation.Children);
        }
            private static FinallyClauseSyntax TryGetFinallySyntax([NotNull] ITryOperation operation)
            {
                var finallySyntax = operation.Finally.Syntax as FinallyClauseSyntax;

                if (finallySyntax == null)
                {
                    // Bug workaround for https://github.com/dotnet/roslyn/issues/27208
                    if (operation.Finally.Syntax is BlockSyntax finallyBlockSyntax)
                    {
                        finallySyntax = finallyBlockSyntax.Parent as FinallyClauseSyntax;
                    }
                }

                return(finallySyntax);
            }
            public override Location VisitTry([NotNull] ITryOperation operation, [CanBeNull] object argument)
            {
                var trySyntax = (TryStatementSyntax)operation.Syntax;

                if (tryFinallyStrategy == TryFinallyLookupKeywordStrategy.PreferTryKeyword)
                {
                    return(trySyntax.TryKeyword.GetLocation());
                }

                FinallyClauseSyntax finallySyntax = TryGetFinallySyntax(operation);

                if (finallySyntax != null)
                {
                    return(finallySyntax.FinallyKeyword.GetLocation());
                }

                return(base.VisitTry(operation, argument));
            }
            private bool ValidateTryOperation(ITryOperation tryOperation)
            {
                // The try operation must have been implicit, as we still analyze it if it isn't implicit
                if (!tryOperation.IsImplicit)
                {
                    return(false);
                }

                // There is no way to pass this check without the finally block being correct,
                // as this try-finally is generated by the compiler. No need to verify
                // the contents of the finally.
                if (tryOperation.Finally == null || !tryOperation.Finally.IsImplicit)
                {
                    return(false);
                }

                // The try statement is otherwise correct, so validate the main body
                return(Validate(tryOperation.Body.Operations));
            }
Exemplo n.º 6
0
 public override IOperation VisitTry(ITryOperation operation, object argument)
 {
     return(new TryStatement(Visit(operation.Body), VisitArray(operation.Catches), Visit(operation.Finally), operation.ExitLabel, ((Operation)operation).SemanticModel, operation.Syntax, operation.Type, operation.ConstantValue, operation.IsImplicit));
 }
Exemplo n.º 7
0
 public virtual void VisitTry(ITryOperation operation)
 {
     DefaultVisit(operation);
 }
Exemplo n.º 8
0
 public override void VisitTry([NotNull] ITryOperation operation)
 {
     base.VisitTry(operation);
 }
 public override void VisitTry([NotNull] ITryOperation operation)
 {
     IncrementStatementCount(operation);
     base.VisitTry(operation);
 }
            public override Location VisitTry([NotNull] ITryOperation operation, [CanBeNull] object argument)
            {
                var syntax = (TryStatementSyntax)operation.Syntax;

                return(syntax.TryKeyword.GetLocation());
            }
Exemplo n.º 11
0
 public override void VisitTry(ITryOperation operation)
 {
     base.VisitTry(operation);
 }
Exemplo n.º 12
0
 public override bool VisitTry([NotNull] ITryOperation operation1, [CanBeNull] IOperation argument)
 {
     return(argument is ITryOperation operation2 && AreBaseOperationsEqual(operation1, operation2));
 }