简体   繁体   中英

How do I turn off the “Convert Extension Method to Plain Static” automatic refactoring in resharper?

When using Resharper, for some reason, when I call an extension method, it automatically converts it into a static method call. This is the so called Convert Extension Method to Plain Static refactoring.

foo.Bar()

becomes

MyStaticExtensions.Bar(foo);

Ironically, it then flags this as a code smell. How do I turn this off?

This feature is embedded in the IntelliSense of Resharper. I'm using Linq-to-sql extensions a lot, so I have disabled this feature: Resharper - Options - IntelliSense - Enable Radiobutton Visual Studio

That doesn't happen for me (Resharper 4.5). Do you have "silent clean up" enabled? (Resharper - options - Code Cleanup).

You can disable this behavior by unchecking Optimize 'using' directives . It's a pity R# has such insane behavior; even more strangely only for a few files. I'd guess it only happens if a static method on Enumerable is called in the current file.

In order to obtain the using sorting and cleaning behavior, I recommend installing Productivity Power Tools and checking Options -> Text Editor -> C# -> Advanced -> Organize Usings -> Place 'System' directives first when sorting usings.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM