Esempio n. 1
0
        public static ICSharpStatement AddStatementsBefore(this ICSharpStatement anchor, IEnumerable <ICSharpStatement> statements,
                                                           ICSharpStatement selectedStatement)
        {
            Contract.Requires(anchor != null);
            Contract.Requires(statements != null);
            Contract.Requires(selectedStatement != null);

            var localAnchor = anchor;
            var parent      = BlockNavigator.GetByStatement(localAnchor);

            Contract.Assert(parent != null, "Can't find parent for the last contract statement.");
            ICSharpStatement result = null;

            foreach (var s in statements)
            {
                localAnchor = parent.AddStatementBefore(s, localAnchor);

                if (s == selectedStatement)
                {
                    result = localAnchor;
                }
            }

            return(result);
        }
        private static bool IsInCaseBlock(ICSharpStatement statement)
        {
            var block = BlockNavigator.GetByStatement(statement);

            while (block != null)
            {
                if (block.Parent is ISwitchStatement)
                {
                    return(true);
                }

                block = block.Parent as IBlock;
            }

            return(false);
        }
        private static bool IsInFinally(ICSharpStatement statement)
        {
            var block = BlockNavigator.GetByStatement(statement);

            while (block != null)
            {
                if (block.Parent is ITryStatement)
                {
                    // Looks ugly, but I don't know how to check that the statement in the finally block only!
                    var tryStatement = (ITryStatement)block.Parent;
                    return(tryStatement.FinallyBlock == block);
                }

                block = block.Parent as IBlock;
            }

            return(false);
        }
Esempio n. 4
0
        public static IBlock GetTargetBlock(ICSharpStatement currentStatement)
        {
            // Looking for the block that is not a part of Try statement
            ICSharpStatement statement = currentStatement;

            while (true)
            {
                IBlock result = BlockNavigator.GetByStatement(statement);
                if (result == null)
                {
                    return(null);
                }

                var tryStatement = result.GetContainingNode <ITryStatement>();
                if (tryStatement == null)
                {
                    return(result);
                }

                statement = tryStatement;
            }
        }