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

                _finallyBlockNestingDepth++;
                Visit(operation.Finally);
                _finallyBlockNestingDepth--;
            }
示例#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));
            }
示例#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));
 }
示例#7
0
 public virtual void VisitTry(ITryOperation operation)
 {
     DefaultVisit(operation);
 }
示例#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());
            }
示例#11
0
 public override void VisitTry(ITryOperation operation)
 {
     base.VisitTry(operation);
 }
示例#12
0
 public override bool VisitTry([NotNull] ITryOperation operation1, [CanBeNull] IOperation argument)
 {
     return(argument is ITryOperation operation2 && AreBaseOperationsEqual(operation1, operation2));
 }