[英]C# - Can't find usage of method when inherited and used through an interface implemented by the subclass
I'm using VisualStudio 2008 and 2010, both with ReSharper, and when I try to lookup for usages of a given method I get no results, despite the method being inherited and then called through an interface. 我正在使用VisualStudio 2008和2010,都使用ReSharper,当我尝试查找给定方法的用法时,我得不到任何结果,尽管该方法是继承的,然后通过接口调用。 What's wrong?
怎么了? Is that a VS/ReSharper bug?
这是VS / ReSharper的错误吗? See the example below:
请参阅以下示例:
using System;
namespace UsageNotFound
{
interface MyInterface
{
void Hello();
}
class SuperClass
{
public void Hello() //NOTE: VS 2008/2010 (with resharper)
seems unable to find usages on this!!!
{
Console.WriteLine("Hi!");
}
}
class SubClass : SuperClass, MyInterface
{
public static MyInterface GetInstance()
{
return new SubClass();
}
}
class Program
{
static void Main(string[] args)
{
SubClass.GetInstance().Hello();
}
}
}
Thanks, Fabrizio 谢谢,Fabrizio
Probably because your SuperClass
doesn't implement the interface. 可能是因为您的
SuperClass
没有实现该接口。 This may cause a problem for ReSharper. 这可能会导致ReSharper出现问题。 Try:
尝试:
class SuperClass : MyInterface
{
public void Hello()
{
Console.WriteLine("Hi!");
}
}
这是一个已知问题:http: //youtrack.jetbrains.net/issue/RSRP-46273 ,没有当前目标修复版本
It's all to do with the order in which SubClass
inherits the Hello()
method from SuperClass
and MyInterface
. 这与
SubClass
从SuperClass
和MyInterface
继承Hello()
方法的SuperClass
MyInterface
。
I'm surprised that you don't get a warning that the SubClass.Hello()
(from implementing the interface definition) will hide the SuperClass.Hello()
. 我很惊讶您没有收到
SubClass.Hello()
(来自实现接口定义)将隐藏SuperClass.Hello()
的SuperClass.Hello()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.