为什么 Resharper 认为具有属性“SomeValue”的内部类在外部类中隐藏同名属性?

发布于 2024-12-27 16:56:18 字数 457 浏览 1 评论 0原文

给出以下代码:

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

    public static string SomeValue { get; set; }
}

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

到底是怎么回事?您有两个不同的引用(Super.SomeValueSuper.Inner.SomeValue)。而且(据我所知)您不能使用一个引用来表示另一个变量。

我发现 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

So尛奶瓶 2025-01-03 16:56:18

我猜测是因为这意味着在内部类中使用 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"; }}
}

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文