JetBrains Rider 2018.2 Help

Code Inspection: Member hides static member from outer class

There is not much wrong with the code example below, at least in it current state where you can observe all declarations at once. However, as the FooNested class would grow and DoSomething() would be not so close to the both declarations of the Bar, someone who reads the code could mistakenly think that DoSomething() uses Foo.Bar and not FooNested.Bar. Furthermore, if someone removes the Foo declaration from FooNested later, they may not notice that the remaining usages of Foo will be returning the value of the Foo.Bar.

Therefore, JetBrains Rider issues a warning to draw your attention to potential problems with this code. There is no quick-fixes because this declaration of the Bar is indeed intended. But if it's not and if you want to safely rename it, press Ctrl+R, R on it to invoke the Rename refactoring.

public class Foo { private static string Bar { get; set; } // some other members private class FooNested { private static string Bar { get; set; } static void DoSomething() { Console.WriteLine(Bar); } } }
Last modified: 21 December 2018

See Also