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


C# SyntaxList.OfType方法代码示例

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


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

示例1: TrouveConditionsParametres

 /// <summary>
 /// Retourne les conditions sur les paramètres dans une listes d'expressions.
 /// </summary>
 /// <param name="expressions">Liste d'expressions.</param>
 /// <param name="paramètres">Les paramètres du constructeur.</param>
 /// <param name="modèleSémantique">Modèle sémantique.</param>
 /// <returns>La liste d'assignations.</returns>
 public static IEnumerable<IfStatementSyntax> TrouveConditionsParametres(SyntaxList<StatementSyntax> expressions, ParameterListSyntax paramètres, SemanticModel modèleSémantique) =>
     expressions
         .OfType<IfStatementSyntax>()
         .Where(e =>
             (e.Condition
                 ?.DescendantNodes()?.OfType<IdentifierNameSyntax>()
                 ?.Any(identifiant => modèleSémantique.GetSymbolInfo(identifiant).Symbol?.Kind == SymbolKind.Parameter)
             ?? false)
         && (e.Statement
                 ?.DescendantNodes()?.OfType<IdentifierNameSyntax>()
                 ?.All(identifiant => modèleSémantique.GetSymbolInfo(identifiant).Symbol?.Kind != SymbolKind.Field)
             ?? false));
开发者ID:JabX,项目名称:controle-point-virgule,代码行数:19,代码来源:Partagé.cs

示例2: ProcessMembers

 private void ProcessMembers(SyntaxList<MemberDeclarationSyntax> members)
 {
     foreach (var namespaceDeclaration in members.OfType<NamespaceDeclarationSyntax>())
     {
         this.ProcessUsingDirectives(namespaceDeclaration.Usings);
         this.ProcessMembers(namespaceDeclaration.Members);
     }
 }
开发者ID:Romanx,项目名称:StyleCopAnalyzers,代码行数:8,代码来源:UsingCodeFixProvider.cs

示例3: CountNamespaces

        private static int CountNamespaces(SyntaxList<MemberDeclarationSyntax> members)
        {
            var result = 0;

            foreach (var namespaceDeclaration in members.OfType<NamespaceDeclarationSyntax>())
            {
                result += 1 + CountNamespaces(namespaceDeclaration.Members);
            }

            return result;
        }
开发者ID:Romanx,项目名称:StyleCopAnalyzers,代码行数:11,代码来源:UsingCodeFixProvider.cs

示例4: RemoveMalformattedStandardText

        private static SyntaxList<XmlNodeSyntax> RemoveMalformattedStandardText(SyntaxList<XmlNodeSyntax> content, SyntaxToken identifier, string preText, string postText, ref string trailingString)
        {
            var regex = new Regex(@"^\s*" + Regex.Escape(preText) + "[^ ]+" + Regex.Escape(postText));
            var item = content.OfType<XmlTextSyntax>().FirstOrDefault();

            if (item == null)
            {
                return content;
            }

            int index = -1;
            foreach (var token in item.TextTokens)
            {
                index++;

                if (token.IsKind(SyntaxKind.XmlTextLiteralNewLineToken))
                {
                    continue;
                }
                else if (token.IsKind(SyntaxKind.XmlTextLiteralToken))
                {
                    string value = token.ValueText.Trim(null);

                    Match match = regex.Match(value);

                    if (!match.Success)
                    {
                        return content;
                    }
                    else if (match.Length == value.Length)
                    {
                        // Remove the token
                        var tokens = item.TextTokens;

                        while (index >= 0)
                        {
                            tokens = tokens.RemoveAt(0);
                            index--;
                        }

                        var newContent = item.WithTextTokens(tokens);

                        return content.Replace(item, newContent);
                    }
                    else
                    {
                        // Remove the tokens before
                        var tokens = item.TextTokens;

                        while (index >= 0)
                        {
                            tokens = tokens.RemoveAt(0);
                            index--;
                        }

                        trailingString = value.Substring(match.Length);

                        var newContent = item.WithTextTokens(tokens);

                        return content.Replace(item, newContent);
                    }
                }
                else
                {
                    return content;
                }
            }

            return content;
        }
开发者ID:Noryoko,项目名称:StyleCopAnalyzers,代码行数:70,代码来源:SA1642SA1643CodeFixProvider.cs

示例5: CollectCondition

        ExpressionSyntax CollectCondition(ExpressionSyntax expressionSyntax, SyntaxList<SwitchLabelSyntax> labels)
        {
            //default
            if (labels.Count == 0 || labels.OfType<DefaultSwitchLabelSyntax>().Any())
                return null;

            var conditionList =
                labels
                    .OfType<CaseSwitchLabelSyntax>()
                    .Select(l => SyntaxFactory.BinaryExpression(SyntaxKind.EqualsExpression, expressionSyntax, l.Value)).ToList();

            //attempt to add parentheses
            //TODO: port InsertParentheses in-full rather than a make-do (but I didn't think I had the time to do a full-port)
            for (int i = 0; i < conditionList.Count; ++i)
            {
                var cond = conditionList[i];
                if (NeedsParentheses((cond.Right)))
                {
                    conditionList[i] = cond.WithRight(SyntaxFactory.ParenthesizedExpression(cond.Right));
                }
            }

            if (conditionList.Count == 1)
                return conditionList.First();

            //combine case labels
            BinaryExpressionSyntax condition = conditionList[0];
            for (int i = 1; i < conditionList.Count; ++i)
            {
                condition = SyntaxFactory.BinaryExpression(SyntaxKind.LogicalOrExpression, condition, conditionList[i]);
            }
            return condition;
        }
开发者ID:alecor191,项目名称:RefactoringEssentials,代码行数:33,代码来源:ConvertSwitchToIfCodeRefactoringProvider.cs


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