"base" qualifier incorrectly replaced with "this" when using same method name as in base but with optional arguments

Snippet

I apologise for my long title but the problem is that I have a case where the "base" qualifier is incorrectly replaced by the "this" qualifier when my child class has the same method name as in the base class with the only difference that the method in the child class is using all optional arguments. So in a way we could almost say that we are shadowing the base classes method. I use this specific case in my integration tests so I am not going to argue about the cleanliness of my solution as I have my reasons for doing it like this that is beyond the scope of this topic.

Here is an example of what I am trying to say. When I do a clean-up of this code the line that reads base.Build() in the Foo class will be replaced with this.Build() which is not the desired behaviour as call this.Build() will result in a StackOverflowException.

namespace ConsoleApplication1
{
    using System;
    using System.Text;
 
    class Program
    {
        static void Main()
        {
            Console.WriteLine(new Foo().Build("test"));
        }
    }
 
    class Foo : FooBase
    {
        public string Build(string someText = "whatever")
        {
            var sb = new StringBuilder();
            sb.Append(base.Build());
            sb.Append(someText);
            return sb.ToString();
        }
    }
 
    class FooBase
    {
        public string Build()
        {
            return string.Empty;
        }
    }
}

 

How can I prevent this from happening? I am aware that in R# 2017.3 it will be possible to disable formatting for a specific line of code using the // @formatter comment, correct?

1 comment
Official comment

Hello Gabriel!

 

Please accept my appologies for the delay in responding.

The specified behavior is caused by StyleCop extension, so the only way is to disable correspondent rule in stylecop.settings file.

Concerning disabling formatting - that's right, this option appears in R# 2017.3, though there's open request for the same feaure for code cleanup - https://youtrack.jetbrains.com/issue/RSRP-466594.

Thank you.

Please sign in to leave a comment.