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


C# LiteralExpressionSyntax.GetLeadingTrivia方法代码示例

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


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

示例1: FormatXmlAsync

		private async Task<Document> FormatXmlAsync(Document document, LiteralExpressionSyntax sleSyntax, CancellationToken cancellationToken)
		{
			var root = await document.GetSyntaxRootAsync(cancellationToken);
			var tree = root.SyntaxTree;

			//Get the character position of the LiteralExpressionSyntax
			FileLinePositionSpan position = tree.GetLineSpan(sleSyntax.Span);
			int cSpace = position.StartLinePosition.Character;

			//Figure out the preceeding trivia since we can't get the column position from GetLineSpan
			var parentTrivia = sleSyntax.GetLeadingTrivia().ToFullString();

			var xml = sleSyntax.GetFirstToken().ValueText;
			var newXmlText = FormatXml(xml);

			//Process each line of the formatted XML and prepend the parent trivia & spaces
			string[] xmlLines = newXmlText.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
			for (int i = 1; i < xmlLines.Length; i++)
			{
				xmlLines[i] = parentTrivia + new String(' ', (cSpace + 2)) + xmlLines[i];
			}

			newXmlText = String.Join("\r\n", xmlLines);
			var newXmlValue = "@\"" + newXmlText + "\"";

			var newNode = SyntaxFactory.LiteralExpression(SyntaxKind.StringLiteralExpression,
				SyntaxFactory.Token(SyntaxTriviaList.Empty, SyntaxKind.StringLiteralToken, newXmlValue, newXmlText, SyntaxTriviaList.Empty));
			var newRoot = root.ReplaceNode(sleSyntax, newNode);
			return document.WithSyntaxRoot(newRoot);
		}
开发者ID:modulexcite,项目名称:GoingBeyondReSharperWithRoslyn_Demo,代码行数:30,代码来源:CodeRefactoringProvider.cs

示例2: VisitLiteralExpression

        public override SyntaxNode VisitLiteralExpression(LiteralExpressionSyntax node)
        {
            if (node.CSharpKind() != SyntaxKind.StringLiteralExpression) return node;

            var pos = node.GetLocation().GetMappedLineSpan();
            var result = OnRewrite(pos.StartLinePosition.Line + 1, pos.StartLinePosition.Character + 1, Source.Lines[pos.StartLinePosition.Line].ToString(), node.Token.ValueText);
            if (result == null) return node;

            var names = result.Split('.');
            ExpressionSyntax newNode = SyntaxFactory.IdentifierName(names.First());
            foreach (var name in names.Skip(1))
            {
                newNode = SyntaxFactory.MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, newNode, SyntaxFactory.IdentifierName(name));
            }

            return newNode.WithLeadingTrivia(node.GetLeadingTrivia()).WithTrailingTrivia(node.GetTrailingTrivia());
        }
开发者ID:GHScan,项目名称:DailyProjects,代码行数:17,代码来源:RoslynTool.cs


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