Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Resharper think that an inner class with property "SomeValue" hides a property with the same name in the outer class?

Tags:

c#

resharper

Given the following code:

public static class Super {     public static class Inner     {         public static string SomeValue { get; set; }     }      public static string SomeValue { get; set; } } 

Resharper tells me that Super.Inner.SomeValue hides a property from the outer class.

How is there hiding going on? You have two distinct references (Super.SomeValue and Super.Inner.SomeValue). And (as far as I know) you cannot use one reference to mean the other variable.

I have found that Resharper is wrong sometimes. But not usually. So I would like to know what it is thinking here.

Any Ideas?

like image 718
Vaccano Avatar asked Jan 18 '12 16:01

Vaccano


1 Answers

I'm guessing because it means using SomeValue in the inner class means you get the value assigned to the inner class rather than the outer class.

Consider this:

public static class Super {   public static class Sub   {     public static string OtherValue {get{return SomeValue;}}      // Remove this line and OtherValue will return Outer     public static string SomeValue { get{return "Inner"; }}   }    public static string SomeValue { get{return "Outer"; }} } 

Currently Super.Sub.OtherValue will return Inner but removing the line I've commented will cause it to return Outer

like image 62
Joey Avatar answered Oct 11 '22 20:10

Joey