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


C# SyntaxNode.ConvertToSingleLine方法代码示例

本文整理汇总了C#中SyntaxNode.ConvertToSingleLine方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxNode.ConvertToSingleLine方法的具体用法?C# SyntaxNode.ConvertToSingleLine怎么用?C# SyntaxNode.ConvertToSingleLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SyntaxNode的用法示例。


在下文中一共展示了SyntaxNode.ConvertToSingleLine方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ConvertToSingleLine

 public SyntaxNode ConvertToSingleLine(SyntaxNode node)
 {
     return node.ConvertToSingleLine();
 }
开发者ID:anshita-arya,项目名称:roslyn,代码行数:4,代码来源:CSharpSyntaxFactsService.cs

示例2: ConvertToSingleLine

 public SyntaxNode ConvertToSingleLine(SyntaxNode node, bool useElasticTrivia = false)
 {
     return node.ConvertToSingleLine(useElasticTrivia);
 }
开发者ID:vslsnap,项目名称:roslyn,代码行数:4,代码来源:CSharpSyntaxFactsService.cs

示例3: GetDisplayName

        /// <summary>
        /// Gets the DisplayName for the given node.
        /// </summary>
        public string GetDisplayName(SemanticModel semanticModel, SyntaxNode node)
        {
            if (node == null)
            {
                return FeaturesResources.paren_Unknown_paren;
            }

            if (CSharpSyntaxFactsService.Instance.IsGlobalAttribute(node))
            {
                return "assembly: " + node.ConvertToSingleLine();
            }

            // Don't discriminate between getters and setters for indexers
            if (node.Parent.IsKind(SyntaxKind.AccessorList) &&
                node.Parent.Parent.IsKind(SyntaxKind.IndexerDeclaration))
            {
                return GetDisplayName(semanticModel, node.Parent.Parent);
            }

            switch (node.Kind())
            {
                case SyntaxKind.ConstructorDeclaration:
                {
                    // The constructor's name will be the name of the class, not ctor like we want
                    var symbol = semanticModel.GetDeclaredSymbol(node);
                    var displayName = symbol.ToDisplayString(Format);
                    var openParenIndex = displayName.IndexOf('(');
                    var lastDotBeforeOpenParenIndex = displayName.LastIndexOf('.', openParenIndex, openParenIndex);

                    var constructorName = symbol.IsStatic ? "cctor" : "ctor";

                    return displayName.Substring(0, lastDotBeforeOpenParenIndex + 1) +
                           constructorName +
                           displayName.Substring(openParenIndex);
                }

                case SyntaxKind.IndexerDeclaration:
                {
                    // The name will be "namespace.class.this[type] - we want "namespace.class[type] Indexer"
                    var symbol = semanticModel.GetDeclaredSymbol(node);
                    var displayName = symbol.ToDisplayString(Format);
                    var openBracketIndex = displayName.IndexOf('[');
                    var lastDotBeforeOpenBracketIndex = displayName.LastIndexOf('.', openBracketIndex, openBracketIndex);

                    return displayName.Substring(0, lastDotBeforeOpenBracketIndex) +
                           displayName.Substring(openBracketIndex) +
                           " Indexer";
                }

                case SyntaxKind.OperatorDeclaration:
                {
                    // The name will be "namespace.class.operator +(type)" - we want namespace.class.+(type) Operator
                    var symbol = semanticModel.GetDeclaredSymbol(node);
                    var displayName = symbol.ToDisplayString(Format);
                    var spaceIndex = displayName.IndexOf(' ');
                    var lastDotBeforeSpaceIndex = displayName.LastIndexOf('.', spaceIndex, spaceIndex);

                    return displayName.Substring(0, lastDotBeforeSpaceIndex + 1) +
                           displayName.Substring(spaceIndex + 1) +
                           " Operator";
                }

                case SyntaxKind.ConversionOperatorDeclaration:
                {
                    // The name will be "namespace.class.operator +(type)" - we want namespace.class.+(type) Operator
                    var symbol = semanticModel.GetDeclaredSymbol(node);
                    var displayName = symbol.ToDisplayString(Format);
                    var firstSpaceIndex = displayName.IndexOf(' ');
                    var secondSpaceIndex = displayName.IndexOf(' ', firstSpaceIndex + 1);
                    var lastDotBeforeSpaceIndex = displayName.LastIndexOf('.', firstSpaceIndex, firstSpaceIndex);

                    return displayName.Substring(0, lastDotBeforeSpaceIndex + 1) +
                           displayName.Substring(secondSpaceIndex + 1) +
                           " Operator";
                }

                case SyntaxKind.UsingDirective:
                {
                    // We want to see usings formatted as simply "Using", prefaced by the namespace they are in
                    var enclosingScopeString = GetEnclosingScopeString(node, semanticModel, Format);
                    return string.IsNullOrEmpty(enclosingScopeString) ? "Using" : enclosingScopeString + " Using";
                }

                case SyntaxKind.ExternAliasDirective:
                {
                    // We want to see aliases formatted as "Alias", prefaced by their enclosing scope, if any
                    var enclosingScopeString = GetEnclosingScopeString(node, semanticModel, Format);
                    return string.IsNullOrEmpty(enclosingScopeString) ? "Alias" : enclosingScopeString + " Alias";
                }

                default:
                {
                    var symbol = semanticModel.GetDeclaredSymbol(node);
                    return symbol != null ? symbol.ToDisplayString(Format) : FeaturesResources.paren_Unknown_paren;
                }
            }
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:100,代码来源:CSharpCodeLensDisplayInfoService.cs


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