本文整理汇总了C#中ObjectCreationExpressionSyntax.ReplaceNode方法的典型用法代码示例。如果您正苦于以下问题:C# ObjectCreationExpressionSyntax.ReplaceNode方法的具体用法?C# ObjectCreationExpressionSyntax.ReplaceNode怎么用?C# ObjectCreationExpressionSyntax.ReplaceNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObjectCreationExpressionSyntax
的用法示例。
在下文中一共展示了ObjectCreationExpressionSyntax.ReplaceNode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UseNameofAsync
private Task<Solution> UseNameofAsync(Document document, SyntaxNode root, ObjectCreationExpressionSyntax objectCreationExpression)
{
var method = objectCreationExpression.Ancestors().OfType<MethodDeclarationSyntax>().First();
var methodParameters = method.ParameterList.Parameters;
var expressionArguments = objectCreationExpression.ArgumentList.Arguments.Select(x => x.Expression).OfType<LiteralExpressionSyntax>();
foreach (var expressionArgument in expressionArguments)
{
foreach (var methodParameter in methodParameters)
{
if (string.Equals((string) methodParameter.Identifier.Value, (string) expressionArgument.Token.Value, StringComparison.OrdinalIgnoreCase))
{
var newExpression = SyntaxFactory.ParseExpression($"nameof({methodParameter.Identifier})");
var newParent = objectCreationExpression.ReplaceNode(expressionArgument, newExpression);
var newRoot = root.ReplaceNode(objectCreationExpression, newParent);
var newDocument = document.WithSyntaxRoot(newRoot);
return Task.FromResult(newDocument.Project.Solution);
}
}
}
return null;
}
示例2: VisitObjectCreationExpression
public override SyntaxNode VisitObjectCreationExpression(ObjectCreationExpressionSyntax node)
{
node = (ObjectCreationExpressionSyntax)base.VisitObjectCreationExpression(node);
// new QueryParameter ("nr", DataType.String, referenceVersion.PatchNumber)
var identifier = node.Type as IdentifierNameSyntax;
if (identifier != null && identifier.HasTrailingTrivia)
{
this.addedAnnotations = true;
return node.ReplaceNode(identifier, identifier.WithoutTrailingTrivia());
}
return node;
}
开发者ID:OliverKurowski,项目名称:StylecopCodeFormatter,代码行数:15,代码来源:SA1008_NoWhitespaceBeforeParenthesis.cs