本文整理汇总了C#中StatementSyntax.DescendantNodes方法的典型用法代码示例。如果您正苦于以下问题:C# StatementSyntax.DescendantNodes方法的具体用法?C# StatementSyntax.DescendantNodes怎么用?C# StatementSyntax.DescendantNodes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StatementSyntax
的用法示例。
在下文中一共展示了StatementSyntax.DescendantNodes方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MakeObjectInitializer
private static Document MakeObjectInitializer(Document document, SyntaxNode root, StatementSyntax statement, ISymbol variableSymbol, SemanticModel semanticModel)
{
var blockParent = statement.FirstAncestorOrSelf<BlockSyntax>();
var objectCreationExpression = statement.DescendantNodes().OfType<ObjectCreationExpressionSyntax>().Single();
var newBlockParent = CreateNewBlockParent(statement, semanticModel, objectCreationExpression, variableSymbol);
var newRoot = root.ReplaceNode(blockParent, newBlockParent);
var newDocument = document.WithSyntaxRoot(newRoot);
return newDocument;
}
示例2: WrapAsync
private static async Task<Document> WrapAsync(Document document, StatementSyntax expressionStatement, CancellationToken token)
{
var identifierNameSyntax =
expressionStatement.DescendantNodes().FirstOrDefault(x => x.IsKind(SyntaxKind.IdentifierName)) as
IdentifierNameSyntax;
if (identifierNameSyntax == null)
return document;
var loggerName = identifierNameSyntax.Identifier.Text;
var expression = SyntaxFactory.ParseExpression(loggerName + ".IsDebugEnabled");
var ifStatement = SyntaxFactory.IfStatement(expression, expressionStatement);
var root = await document.GetSyntaxRootAsync(token);
root = root.ReplaceNode(expressionStatement, ifStatement);
return document.WithSyntaxRoot(root);
}
示例3: IsPassedAsArgument
private static bool IsPassedAsArgument(StatementSyntax statement, SemanticModel semanticModel, ILocalSymbol identitySymbol)
{
if (statement == null) return false;
var args = statement.DescendantNodes().OfKind<ArgumentSyntax>(SyntaxKind.Argument);
foreach (var arg in args)
{
var argSymbol = semanticModel.GetSymbolInfo(arg.Expression).Symbol;
if (identitySymbol.Equals(argSymbol)) return true;
}
return false;
}