本文整理汇总了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));
示例2: ProcessMembers
private void ProcessMembers(SyntaxList<MemberDeclarationSyntax> members)
{
foreach (var namespaceDeclaration in members.OfType<NamespaceDeclarationSyntax>())
{
this.ProcessUsingDirectives(namespaceDeclaration.Usings);
this.ProcessMembers(namespaceDeclaration.Members);
}
}
示例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;
}
示例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;
}
示例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;
}