Michal Hosala Michal Hosala - 7 months ago 9
Vb.net Question

How to run case correction on solution?

I have a tiny roslyn based application for code formatting of VB.NET/C# projects based on a sample provided at codeplex. This application is a new version of older code formatter that I developed based on DTE in which I programmatically run Visual Studio command

Edit.FormatDocument
on every file in a particular solution like this:

projectItem.Document.DTE.ExecuteCommand("Edit.FormatDocument");


This is no longer acceptable, therefore I started developing the new version that would perform the same task as FormatDocument command. One of the features of this command in VB.NET source file is that it corrects casing for both keywords and names, e.g.:


  • public
    becomes
    Public
    ,

  • variable defined as
    fooBar
    but used as
    foobar
    => usage changes to
    fooBar

  • etc.



First I thought that
Microsoft.CodeAnalysis.Formatting.Formatter.FormatAsync(...)
alone would do the job but it seems like it only takes care of the whitespaces. Therefore I started looking elsewhere and discovered method
Microsoft.CodeAnalysis.CaseCorrection.CaseCorrector.CaseCorrectAsync(...)
but the
CaseCorrector
class is unfortunately
internal
. It makes me wonder though, whether it isn't a bug taking into account method
CaseCorrectAsync
being
public
.

Is there a reasonable way to run case correction in my new roslyn based app?

Answer

Correct solution really is to use CaseCorrector class which was intended to be public as per comments in a roslyn bug report. So to address this issue now one has to make CaseCorrector public, build roslyn locally and use the modified binaries.

Comments