Code cleanup is adding explicit parameter types to lambdas

When I run code cleanup ReSharper is adding redundant explicit parameter types to all my lambdas. Then ReSharper complains that I don't need the redundant explicit types. I cannot find anywhere in the ReSharper nor Visual Studio 2022 options to turn off these explicit types. Does anyone know how to prevent these?

Before code cleanup:

After code cleanup:

0
8 comments

Hello Darryl,

Have you tried ReSharper | Options | Code Editing | C# | Syntax Style | ‘var’ usage in declarations options for configuring this behavior?

As for ReSharper complaining about redundant explicit type, could it be that it's VS suggestion, not ReSharper one? Unfortunately, it's not clear from the provided screenshot.

Thank you.

0

Thank you for the response. I currently have the setting you have referenced set to what I believe would not cause explicit types to be used. Here's a screenshot of the relevant settings area:

As for whether ReSharper or Visual Studio is making the suggestion, it does seem to be ReSharper offering the syntax changes. I realize that I could just disable this inspection, but I'd prefer to not have the explicit types for the lambda parameters added in the first place. My fear is that this is something Visual Studio is doing with no corresponding option to disable it. It would be wonderful if the “Remove parameter type specification” for lambdas could be integrated into the code cleanup.

0

I should also point out that I do have the “Remove code redundancies” option selected in the code cleanup specification:

0

Hello Darryl,

As far as I see from the screenshot of ReSharper options page, the settings ‘var’ usage in declarations are overridden by some other configuration file. Could it be .editorconfig? 

0

There is an .editorconfig, but I'm not seeing that same note about the setting being overridden when I hover it in the ReSharper options. I deleted the .editorconfig and ran code cleanup again and it still adds the explicit lambda parameter types back in. Here is the area of .editorconfig related to var usage:

0

Hello Darryl,

Could you please disable the following option and let me know if it makes any difference - ReSharper | Options | Code Editing | General Formatter Style | Read code style from .editorconfig files.

Thank you.

0

Same behavior, unfortunately. I've done a bit more research and I believe this is a Visual Studio thing that was implemented to support default values for parameters. I don't believe ReSharper is adding the explicit parameter types, but it would be nice if there were an additional option on the code cleanup profiles to remove redundant explicit parameter types in lambdas. As it stands today I will just have to continue using the ReSharper functionality to remove these after running code cleanup. It turns code cleanup into a two-step process, but I'm not sure what else I can do.

0

Hello Darryl,

I've filed a corresponding feature request - Include removing redundant lambda parameter type in code cleanup. Feel free to comment or vote for it.

Let me know if you have any questions or concerns.

0

Please sign in to leave a comment.