当前位置: 首页>>代码示例>>C#>>正文


C# BlockSyntax.DescendantNodes方法代码示例

本文整理汇总了C#中BlockSyntax.DescendantNodes方法的典型用法代码示例。如果您正苦于以下问题:C# BlockSyntax.DescendantNodes方法的具体用法?C# BlockSyntax.DescendantNodes怎么用?C# BlockSyntax.DescendantNodes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BlockSyntax的用法示例。


在下文中一共展示了BlockSyntax.DescendantNodes方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: IsAccessed

        private bool IsAccessed(
            SemanticModel semanticModel,
            ISymbol outSymbol, 
            BlockSyntax enclosingBlockOfLocalStatement,
            LocalDeclarationStatementSyntax localStatement, 
            ArgumentSyntax argumentNode,
            CancellationToken cancellationToken)
        {
            var localStatementStart = localStatement.Span.Start;
            var argumentNodeStart = argumentNode.Span.Start;
            var variableName = outSymbol.Name;

            // Walk the block that the local is declared in looking for accesses.
            // We can ignore anything prior to the actual local declaration point,
            // and we only need to check up until we reach the out-argument.
            foreach (var descendentNode in enclosingBlockOfLocalStatement.DescendantNodes())
            {
                var descendentStart = descendentNode.Span.Start;
                if (descendentStart <= localStatementStart)
                {
                    // This node is before the local declaration.  Can ignore it entirely as it could
                    // not be an access to the local.
                    continue;
                }

                if (descendentStart >= argumentNodeStart)
                {
                    // We reached the out-var.  We can stop searching entirely.
                    break;
                }

                if (descendentNode.IsKind(SyntaxKind.IdentifierName))
                {
                    // See if this looks like an accessor to the local variable syntactically.
                    var identifierName = (IdentifierNameSyntax)descendentNode;
                    if (identifierName.Identifier.ValueText == variableName)
                    {
                        // Confirm that it is a access of the local.
                        var symbol = semanticModel.GetSymbolInfo(identifierName, cancellationToken).Symbol;
                        if (outSymbol.Equals(symbol))
                        {
                            // We definitely accessed the local before the out-argument.  We 
                            // can't inline this local.
                            return true;
                        }
                    }
                }
            }

            // No accesses detected
            return false;
        }
开发者ID:otawfik-ms,项目名称:roslyn,代码行数:52,代码来源:CSharpInlineDeclarationDiagnosticAnalyzer.cs

示例2: GetLabelSymbols

            private void GetLabelSymbols(BlockSyntax body, SemanticModel model, List<ISymbol> list)
            {
                var labels = body.DescendantNodes().OfType<LabeledStatementSyntax>();
                foreach (var n in labels)
                {
                    // Label: -> 'Label' is token
                    var sym = model.GetDeclaredSymbol(n);
                    list.Add(sym);
                }

                var swlabels = body.DescendantNodes().OfType<SwitchLabelSyntax>();
                foreach (var n in swlabels)
                {
                    // label value has NO symbol, Type is expr's type
                    // e.g. case "A": -> string type
                    // var info1 = model.GetTypeInfo(n.Value);
                    // var info2 = model.GetSymbolInfo(n.Value);
                    var sym = model.GetDeclaredSymbol(n);
                    list.Add(sym);
                }
            }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:21,代码来源:SymbolKeyTestBase.cs

示例3: GetAnonymousTypeOrFuncSymbols

            private void GetAnonymousTypeOrFuncSymbols(BlockSyntax body, SemanticModel model, List<ISymbol> list)
            {
                IEnumerable<ExpressionSyntax> exprs = body.DescendantNodes().OfType<SimpleLambdaExpressionSyntax>();
                IEnumerable<ExpressionSyntax> tmp = body.DescendantNodes().OfType<ParenthesizedLambdaExpressionSyntax>();
                exprs = exprs.Concat(tmp);
                tmp = body.DescendantNodes().OfType<AnonymousMethodExpressionSyntax>();
                exprs = exprs.Concat(tmp);

                tmp = body.DescendantNodes().OfType<AnonymousObjectCreationExpressionSyntax>();
                exprs = exprs.Concat(tmp);

                foreach (var expr in exprs)
                {
                    GetAnonymousExprSymbols(expr, model, list);
                }
            }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:16,代码来源:SymbolKeyTestBase.cs

示例4: HasNotNullContract

        static bool HasNotNullContract(SemanticModel semanticModel, IParameterSymbol parameterSymbol, BlockSyntax bodyStatement)
        {
            foreach (var expressions in bodyStatement.DescendantNodes().OfType<ExpressionStatementSyntax>())
            {
                var identifiers = expressions.DescendantNodes().OfType<IdentifierNameSyntax>();

                if (Enumerable.SequenceEqual(identifiers.Select(i => i.Identifier.Text), new List<string>() { "Contract", "Requires", parameterSymbol.Name }))
                {
                    return true;
                }
            }
            return false;
        }
开发者ID:alecor191,项目名称:RefactoringEssentials,代码行数:13,代码来源:ContractRequiresNotNullCodeRefactoringProvider.cs

示例5: TryFindEndAPMCallSyntaxNode

        private static InvocationExpressionSyntax TryFindEndAPMCallSyntaxNode(BlockSyntax lambdaBlock, string methodNameBase)
        {
            // TODO: Check for correct signature, etc.
            // This can be done much smarter by e.g. using the BeginXxx method symbol, looking up the corresponding EndXxx symobl, and filtering on that.

            try
            {
                // TODO: Also considier IdentifierName EndXxx instances.
                var endXxxExpression = lambdaBlock.DescendantNodes()
                                                  .OfType<MemberAccessExpressionSyntax>()
                                                  .Where(node => NodeIsNotContainedInLambdaExpression(node, lambdaBlock))
                                                  .First(stmt => stmt.Name.ToString().Equals("End" + methodNameBase));

                return (InvocationExpressionSyntax)endXxxExpression.Parent;
            }
            catch (InvalidOperationException)
            {
                return null;
            }
        }
开发者ID:modulexcite,项目名称:Asyncifier,代码行数:20,代码来源:CodeRefactoringProvider.cs

示例6: IsIterationVariableWritten

 private static bool IsIterationVariableWritten(SemanticModel semanticModel, BlockSyntax forBlock, List<ILocalSymbol> iterableSymbols)
 {
     var forDescendants = forBlock.DescendantNodes();
     var assignments = (from assignmentExpression in forDescendants.OfType<AssignmentExpressionSyntax>()
                        let assignmentLeftSymbol = semanticModel.GetSymbolInfo(assignmentExpression.Left).Symbol
                        where iterableSymbols.Any(i => i.Equals(assignmentLeftSymbol))
                        select assignmentExpression).ToList();
     if (assignments.Any()) return true;
     var refs = (from argument in forDescendants.OfType<ArgumentSyntax>()
                 where argument.RefOrOutKeyword != null
                 let argumentExpressionSymbol = semanticModel.GetSymbolInfo(argument.Expression).Symbol
                 where iterableSymbols.Any(i => i.Equals(argumentExpressionSymbol))
                 select argument).ToList();
     if (refs.Any()) return true;
     var postfixUnaries = (from postfixUnaryExpression in forDescendants.OfType<PostfixUnaryExpressionSyntax>()
                           let operandSymbol = semanticModel.GetSymbolInfo(postfixUnaryExpression.Operand).Symbol
                           where iterableSymbols.Any(i => i.Equals(operandSymbol))
                           select postfixUnaryExpression).ToList();
     if (postfixUnaries.Any()) return true;
     var prefixUnaries = (from postfixUnaryExpression in forDescendants.OfType<PrefixUnaryExpressionSyntax>()
                           let operandSymbol = semanticModel.GetSymbolInfo(postfixUnaryExpression.Operand).Symbol
                           where iterableSymbols.Any(i => i.Equals(operandSymbol))
                           select postfixUnaryExpression).ToList();
     if (prefixUnaries.Any()) return true;
     return false;
 }
开发者ID:julianosaless,项目名称:code-cracker,代码行数:26,代码来源:ForInArrayAnalyzer.cs

示例7: UpdateMethodBody

        private BlockSyntax UpdateMethodBody(BlockSyntax blockSyntax, TypeSyntax returnTypeSyntax, ParameterListSyntax parameterListSyntax)
        {
            if (blockSyntax != null)
            {
                //var specialType = _typeTranslation.FirstOrDefault(tt => ExtractRoslynSymbol(tt.ActualType).ToDisplayString() == returnTypeSyntax.ToFullString().Replace("global::", ""));
                var specialType = _typeTranslation.FirstOrDefault(tt => PrettyTypeName(tt.ActualType) == returnTypeSyntax.ToFullString().Replace("global::", ""));

                if (specialType != null)
                {
                    blockSyntax = SyntaxFactory.Block(
                        blockSyntax.Statements.Select(s => s.IsKind(SyntaxKind.ReturnStatement) ?
                           WrapReturnStatement(s as ReturnStatementSyntax, specialType) :
                           s
                    ).ToArray());
                }

                var parameterIdentifierNodes = blockSyntax.DescendantNodes()
                    .OfType<IdentifierNameSyntax>()
                    .Where(i => parameterListSyntax.Parameters
                        .Any(p => p.Identifier.ToFullString() == i.ToFullString()));
                blockSyntax = blockSyntax.ReplaceNodes(parameterIdentifierNodes, (originalNode, rewrittenNode) => WrapForwardedIdentifier(rewrittenNode, parameterListSyntax));
            }

            return blockSyntax;
        }
开发者ID:herskinduk,项目名称:AutoWrapping,代码行数:25,代码来源:RoslynTypeRewriter.cs

示例8: HasReturnContract

        static bool HasReturnContract(BlockSyntax bodyStatement, string returnType)
        {
            var workspace = new AdhocWorkspace();

            foreach (var expression in bodyStatement.DescendantNodes().OfType<ExpressionStatementSyntax>())
            {
                var formatted = Formatter.Format(expression, workspace).ToString();

                if (formatted == $"Contract.Ensures(Contract.Result<{returnType}>() != null);")
                    return true;

                if (formatted == $"Contract.Ensures(null != Contract.Result<{returnType}>());")
                    return true;
            }
            return false;
        }
开发者ID:alecor191,项目名称:RefactoringEssentials,代码行数:16,代码来源:ContractEnsuresNotNullReturnRefactoringProvider.cs


注:本文中的BlockSyntax.DescendantNodes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。