Пример #1
0
            public bool IsPartOfUsingConstruct(InvocationExpressionSyntax syntax)
            {
                if (syntax == null)
                {
                    throw new ArgumentNullException(nameof(syntax));
                }

                ParentNodeType pnt = ParentNodeType.FindTerminalParentNode(syntax);

                return(pnt.Ok ?? false);
            }
Пример #2
0
            public (bool PartOfInlineDeclUsing, VariableDeclarationSyntax ParentNode) IsPartOfInlineDeclUsingConstruct(InvocationExpressionSyntax syntax)
            {
                if (syntax == null)
                {
                    throw new ArgumentNullException(nameof(syntax));
                }
                ParentNodeType            pnt = ParentNodeType.FindTerminalParentNode(syntax);
                VariableDeclarationSyntax pNode;
                bool ret;

                if (true == pnt.Ok)
                {
                    switch (pnt.TerminalNode?.Kind())
                    {
                    default:
                    case null:
                        ret   = false;
                        pNode = null;
                        break;

                    case SyntaxKind.LocalDeclarationStatement:
                        ret   = true;
                        pNode = pnt.TerminalNode.ChildNodes().OfType <VariableDeclarationSyntax>().FirstOrDefault();
                        Debug.Assert(pNode != null);
                        break;

                    case SyntaxKind.UsingStatement:
                        (ret, pNode) = HasVariableDeclarationChildNode((UsingStatementSyntax)pnt.TerminalNode);
                        Debug.Assert(!ret || pNode != null);
                        break;
                    }
                }
                else
                {
                    ret   = false;
                    pNode = null;
                }
                Debug.Assert(!ret || pNode != null);
                return(ret, pNode);
            }
Пример #3
0
            public (bool ok, BlockSyntax ContainingBlockSyntax, UsingStatementSyntax UsingStatementSyntax) FindBlockOrUsingStatement(InvocationExpressionSyntax syntax)
            {
                BlockSyntax          usingDeclarationBlock;
                UsingStatementSyntax usingStateSyntax;
                bool           ok;
                ParentNodeType pnt = ParentNodeType.FindTerminalParentNode(syntax);

                if (true == pnt.Ok)
                {
                    switch (pnt.TerminalNode?.Kind())
                    {
                    default:
                    case null:
                        ok = false;
                        usingDeclarationBlock = null;
                        usingStateSyntax      = null;
                        break;

                    case SyntaxKind.LocalDeclarationStatement:
                        (ok, usingDeclarationBlock) =
                            FindBlockSyntaxAncestor((LocalDeclarationStatementSyntax)pnt.TerminalNode);
                        usingStateSyntax = null;
                        break;

                    case SyntaxKind.UsingStatement:
                        usingStateSyntax      = (UsingStatementSyntax)pnt.TerminalNode;
                        usingDeclarationBlock = null;
                        ok = true;
                        //(ret, pNode) = HasVariableDeclarationChildNode((UsingStatementSyntax)pnt.TerminalNode);
                        //Debug.Assert(!ret || pNode != null);
                        break;
                    }
                }
                else
                {
                    ok = false;
                    usingDeclarationBlock = null;
                    usingStateSyntax      = null;
                }

                Debug.Assert(!ok || ((usingStateSyntax == null) != (usingDeclarationBlock == null)));
                Debug.Assert(ok || (usingStateSyntax == null && usingDeclarationBlock == null));
                return(ok, usingDeclarationBlock, usingStateSyntax);

                (bool FoundBlockSyntax, BlockSyntax Bs) FindBlockSyntaxAncestor(LocalDeclarationStatementSyntax ldss)
                {
                    BlockSyntax bs      = null;
                    SyntaxNode  current = ldss;

                    while (bs == null && current != null)
                    {
                        if (current is BlockSyntax blk)
                        {
                            bs = blk;
                        }
                        else
                        {
                            current = current.Parent;
                        }
                    }

                    return(bs != null, bs);
                }
            }