Why no suggestion to add new parameters to a method instead of just creating a new overload?
Follow

I have an existing method with a single parameter in a project which compiles. I added a few new ones to the caller and naturally there's a compile error. I noticed read lines under all the parameters including the original one. Not sure why the original one was included. I hit alt-enter and I was expecting to see one of the suggestions to add the new parameters to the method signature. It wasn't there. There was a suggestion to add new overload. So I chose it and copied the new overload signature on top of the old one and deleted the new overload.

Are there conditions when new parameters addition won't work?

Votes

0

Share

I tried to reproduce the issue in R# 8.2.2 but no luck. There was "Add {...} parameter to {...}" quickfix in AltEnter menu. If you are able to reproduce the issue in R# 8.2.2, could you please send me a sample solution which will demonstrate it?

Does it have anything to do with the access level of the method? Adding a parameter to a public method (or even protected or friend/internal) is not a safe refactor. Adding a parameter to a private method could be a safe refactor.

Changing a public method's signare is never safe. You can do it, it's just not safe. Public methods are accessible from outside of the project and the solution which means you would break any code that was using the method by adding a new parameter to it.

abdu wrote:

Regardless, R# should never stop the developer from doing something if it's allowable in the language.

R# is not stopping the developer from doing anything. As you already stated, you were able to add the parameter to the method. R# did not stop you from doing that.

I thought you were saying that R# doesn't offer that option for public methods and I said this shouldn't matter and I don't know if you're suggesting that R# should behave that way or you're just giving a general C# coding advice.

I don't know if that is the the reason. That's why I asked it as a question instead of stating it as an answer. I know the R# team has made decisions not to offer certain unsafe code refactorings. Although, they do have rename refactoring which would be equally as unsafe so that might not be the reason.

Anway, even if R# is not providing a 1-click refactor for something, that is very different than R# getting in the developer's way and not allowing you to do something. R# does not prevent the developer from doing anything at all. You can still do whatever you want to your code. It's just bad when an automated process that you trust and rely on breaks your code because it did something that wasn't safe.

It also happens in EAP 9. I added two new parameters to a caller. The callee is a public static method. The VS error is 'No overload for method 'xxxxxx' takes 6 arguments. R# has only one suggestion 'Create Overload for 'xxxxx''. Are there some situations when R# won't suggest to add the new patameters?