Problem
This issue impacts both ReSharper and Rider
Inactive preprocessor branches are not taken into account on Refactoring. For example, consider the following dependency injection configuration of an ASP.NET program:
using Microsoft.Extensions.Logging;
// some code ...
#if DEBUG
options.EnableSensitiveDataLogging();
#else
options.LogTo(System.Console.WriteLine, LogLevel.None);
#endif
If the current launch profile is Release, code inspection will suggest deleting the unused using Microsoft.Extensions.Logging; . It will cause issue if the program is on Release.
The same issue happens on Unity as well, like using #if UNITY_WEBGL, #if UNITY_EDITOR, etc.
Cause [Optional]
ReSharper (Rider ReSharper backend) will respect the preprocessor settings of the current context. It causes the unused preprocessor will not be taken during analysis. It's a critical issue impacted R#/Rider basic implementation.
Resolution
A workaround is enclosing the mis-refactoring context with the same preprocessor directives, R#/Rider will skip the code during Code Cleanup. For example, the previous code sample:
#if DEBUG
using Microsoft.Extensions.Logging;
#endif
// some code ...
#if DEBUG
options.EnableSensitiveDataLogging();
#else
options.LogTo(System.Console.WriteLine, LogLevel.None);
#endif
Comments
0 comments
Please sign in to leave a comment.