为什么Resharper认为具有属性"SomeValue"的内部类隐藏了外部类中具有相同名称的属性?

Vac*_*ano 28 c# resharper

给出以下代码:

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

    public static string SomeValue { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

Resharper告诉我Super.Inner.SomeValue隐藏了外部类的属性.

怎么藏起来?你有两个不同的引用(Super.SomeValueSuper.Inner.SomeValue).并且(据我所知)你不能使用一个引用来表示另一个变量.

我发现Resharper有时候是错的.但通常不会.所以我想知道这里的想法.

有任何想法吗?

Joe*_*oey 33

我猜是因为它意味着SomeValue在内部类中使用意味着你获得分配给内部类而不是外部类的值.

考虑一下:

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"; }}
}
Run Code Online (Sandbox Code Playgroud)

目前Super.Sub.OtherValue将返回,Inner但删除我评论的行将导致它返回Outer