本文整理汇总了C#中SyntaxToken.WithConvention方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxToken.WithConvention方法的具体用法?C# SyntaxToken.WithConvention怎么用?C# SyntaxToken.WithConvention使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SyntaxToken
的用法示例。
在下文中一共展示了SyntaxToken.WithConvention方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RenameAsync
private Task<Solution> RenameAsync(Document document, SyntaxNode root, SyntaxToken identifier)
{
var identifierParent = identifier.Parent;
var newIdentifier = default(SyntaxToken);
do
{
var parentAsField = identifierParent as FieldDeclarationSyntax;
if (parentAsField != null)
{
if (parentAsField.Modifiers.Any(x => new[] { SyntaxKind.InternalKeyword, SyntaxKind.ProtectedKeyword, SyntaxKind.PublicKeyword }.Any(keyword => x.IsKind(keyword))))
{
newIdentifier = identifier.WithConvention(NamingConvention.UpperCamelCase);
}
else
{
newIdentifier = identifier.WithConvention(NamingConvention.UnderscoreLowerCamelCase);
}
break;
}
if (identifierParent is PropertyDeclarationSyntax ||
identifierParent is MethodDeclarationSyntax ||
identifierParent is ClassDeclarationSyntax ||
identifierParent is StructDeclarationSyntax)
{
newIdentifier = identifier.WithConvention(NamingConvention.UpperCamelCase);
break;
}
if (identifierParent is LocalDeclarationStatementSyntax || identifierParent is ParameterSyntax)
{
newIdentifier = identifier.WithConvention(NamingConvention.LowerCamelCase);
break;
}
if (identifierParent is InterfaceDeclarationSyntax)
{
newIdentifier = identifier.WithConvention(NamingConvention.InterfacePrefixUpperCamelCase);
break;
}
identifierParent = identifierParent.Parent;
} while (identifierParent != null);
var newParent = identifierParent.ReplaceToken(identifier, newIdentifier);
var newRoot = root.ReplaceNode(identifierParent, newParent);
return Task.FromResult(document.WithSyntaxRoot(newRoot).Project.Solution);
}
示例2: CheckNaming
private void CheckNaming(SyntaxToken currentIdentifier, string memberType, NamingConvention convention, SyntaxNodeAnalysisContext context)
{
var conventionedIdentifier = currentIdentifier.WithConvention(convention);
if (conventionedIdentifier.Text != currentIdentifier.Text)
{
context.ReportDiagnostic(Diagnostic.Create(Rule, currentIdentifier.GetLocation(), memberType, currentIdentifier.Text, conventionedIdentifier.Text));
}
}