There have been some changes to Roslyn since my last post and some of my old examples don’t compile.
CustomWorkspace has been replaced by AdHocWorkspace
Creating a class from scratch is now:
AdhocWorkspace cw = new AdhocWorkspace(); OptionSet options = cw.Options; options = options.WithChangedOption( CSharpFormattingOptions.NewLinesForBracesInMethods, false ); options = options.WithChangedOption( CSharpFormattingOptions.NewLinesForBracesInTypes, false ); SyntaxNode formattedNode = Formatter.Format( cu, cw, options ); StringBuilder sb = new StringBuilder(); using ( StringWriter writer = new StringWriter( sb ) ) { formattedNode.WriteTo( writer ); }
Note that some of the CSharpFormattingOptions syntax changed, too.
In our simple getter and setter, the BinaryExpression used for assigment is now an AssignmentExpression.
PropertyDeclarationSyntax property = SF.PropertyDeclaration( SF.ParseTypeName( "String" ), SF.Identifier( "A" ) ) .AddModifiers( SF.Token( SyntaxKind.PublicKeyword ) ) .AddAccessorListAccessors( SF.AccessorDeclaration( SyntaxKind.GetAccessorDeclaration, SF.Block( SF.List( new [] { SF.ReturnStatement( SF.IdentifierName( "_a" ) ) } ) ) ), SF.AccessorDeclaration( SyntaxKind.SetAccessorDeclaration, SF.Block( SF.List( new [] { SF.ExpressionStatement( SF.AssignmentExpression( SyntaxKind.SimpleAssignmentExpression, SF.IdentifierName( "_a" ), SF.IdentifierName( "value" ) ) ) } ) ) ) ) ;
Everything else from my old example project seems to compile.