Code Formatting in Roslyn SDK Preview

假如想象 提交于 2019-12-05 00:35:08

You can format SyntaxNodes using the Microsoft.CodeAnalysis.Formatting.Formatter like this (if you have a workspace):

using Microsoft.CodeAnalysis.Formatting;

var formattedResult = Formatter.Format(syntaxNode, workspace);

EDIT: As Jeroen wrote in a comment, if you don't have a workspace and don't need workspace-specific formatting settings, you can just create one:

var workspace = MSBuildWorkspace.Create();

Roslyn has changed quite a lot since the CTP.

Documentation is now here: https://roslyn.codeplex.com/

Follow the link to https://roslyn.codeplex.com/documentation, click on "Samples and Walkthroughs", then open up the demo solution "FormatSolution - A console application that formats all C# and VB source files in a solution.".

Unfortunately, I don't think its possible to quickly get formatting working any more, as you have to add the code to a new solution.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!