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. What's wrong? Is that a VS/ReSharper bug? 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
Probably because your SuperClass
doesn't implement the interface. This may cause a problem for 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
.
I'm surprised that you don't get a warning that the SubClass.Hello()
(from implementing the interface definition) will hide the SuperClass.Hello()
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.