Warning
Please back up your projects before trying.
Known Issues:
- If an event in a
UserControl
references a misnamed method in the code behind, the method will be renamed in code behind but not in xaml. This behavior is not present in Microsoft's fixer.
Important
Just like Microsoft's built-in IDE1006 fixer, it will rename a symbol even if the new name is already being used causing CS0102 and CS0229 errors.
When installed, there should be an additional option to fix naming style violations but this one has the ability to fix all enabled.
The code fix works by simulating a simple code change on Microsoft's NamingStyleCodeFixProvider
so instead of:
public override FixAllProvider? GetFixAllProvider()
{
// Currently Fix All is not supported for naming style violations.
return null;
}
It is:
public override FixAllProvider? GetFixAllProvider()
{
// See https://github.com/dotnet/roslyn/blob/main/docs/analyzers/FixAllProvider.md for more information on Fix All Providers
return WellKnownFixAllProviders.BatchFixer;
}
And then overriding GetChangedSolutionAsync
in FixNameCodeAction
:
protected override async Task<Solution> GetChangedSolutionAsync(CancellationToken cancellationToken)
{
return await FixAsync(_startingSolution, _options, _symbol, _newName, cancellationToken);
}
protected static async Task<Solution> FixAsync(Solution startingSolution, OptionSet options, ISymbol symbol, string fixedName, CancellationToken cancellationToken)
{
return await Renamer.RenameSymbolAsync(startingSolution, symbol, fixedName, options, cancellationToken).ConfigureAwait(false);
}
I created a test project but I didn't have the time to figure out how to apply code fixes using MsBuild so just ignore it.