Formatting C# with Roslyn

There’s already been a change to Roslyn that made my last bit of code obsolete. CustomWorkspace no longer requires a string in the constructor and is just:

new CustomWorkspace()

I found out how to change the formatting on the output. We can do this:

CustomWorkspace cw = new CustomWorkspace();
OptionSet options = cw.GetOptions();
options = options.WithChangedOption( CSharpFormattingOptions.OpenBracesInNewLineForMethods, false );
options = options.WithChangedOption( CSharpFormattingOptions.OpenBracesInNewLineForTypes, false );
SyntaxNode formattedNode = Formatter.Format( cu, cw, options );

With this change, our output code is now:

using System;
using System.Generic;

namespace MyNamespace {
    private partial class MyClass {
    }
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s