本文整理汇总了C#中ExpressionSyntax.DescendentNodesAndSelf方法的典型用法代码示例。如果您正苦于以下问题:C# ExpressionSyntax.DescendentNodesAndSelf方法的具体用法?C# ExpressionSyntax.DescendentNodesAndSelf怎么用?C# ExpressionSyntax.DescendentNodesAndSelf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ExpressionSyntax
的用法示例。
在下文中一共展示了ExpressionSyntax.DescendentNodesAndSelf方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RewritePostfixUnarys
protected ExpressionSyntax RewritePostfixUnarys(ExpressionSyntax node)
{
var expressions = node.DescendentNodesAndSelf().OfType<PostfixUnaryExpressionSyntax>().ToArray();
if (expressions.Length == 0)
return node;
List<string> names = new List<string> (expressions.Length);
foreach (var expr in expressions)
{
if (expr.Kind != SyntaxKind.PostIncrementExpression && expr.Kind != SyntaxKind.PostDecrementExpression)
continue; // These aren't the droids we're looking for.
IdentifierNameSyntax name = FindIdentifierName (expr);
if (name == null)
continue; // We didn't find a name
if (names.Contains (name.PlainName))
{
var newExpr = GetLogExpression (name.PlainName, expr);
node = node.ReplaceNode (expr, newExpr);
}
else
names.Add (name.PlainName);
}
// We'll use a string builder construct our expression.
StringBuilder builder = new StringBuilder ("LogPostfixValues ((");
builder.Append (node.ToString());
builder.Append ("), ");
bool found = false;
foreach (string name in names)
{
if (found)
builder.Append (", ");
// We need to specify our generic types so we match
// the params argument type
builder.Append ("new Tuple<string, object> (\"");
builder.Append (name);
builder.Append ("\", ");
builder.Append (name);
builder.Append (")");
found = true;
}
if (!found)
return node; // We didn't find any usable expressions
builder.Append (")");
// Parse and return our new expression.
return Syntax.ParseExpression (builder.ToString());
}