当前位置: 首页>>代码示例>>C#>>正文


C# SyntaxToken.WithConvention方法代码示例

本文整理汇总了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);
        }
开发者ID:nemec,项目名称:VSDiagnostics,代码行数:49,代码来源:NamingConventionsCodeFix.cs

示例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));
     }
 }
开发者ID:nemec,项目名称:VSDiagnostics,代码行数:8,代码来源:NamingConventionsAnalyzer.cs


注:本文中的SyntaxToken.WithConvention方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。