![](/img/trans.png)
[英]C# method that can optionally be implemented by subclass, without a base method
[英]C# - Can't find usage of method when inherited and used through an interface implemented by the subclass
我正在使用VisualStudio 2008和2010,都使用ReSharper,當我嘗試查找給定方法的用法時,我得不到任何結果,盡管該方法是繼承的,然后通過接口調用。 怎么了? 這是VS / ReSharper的錯誤嗎? 請參閱以下示例:
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();
}
}
}
謝謝,Fabrizio
可能是因為您的SuperClass
沒有實現該接口。 這可能會導致ReSharper出現問題。 嘗試:
class SuperClass : MyInterface
{
public void Hello()
{
Console.WriteLine("Hi!");
}
}
這是一個已知問題:http: //youtrack.jetbrains.net/issue/RSRP-46273 ,沒有當前目標修復版本
這與SubClass
從SuperClass
和MyInterface
繼承Hello()
方法的SuperClass
MyInterface
。
我很驚訝您沒有收到SubClass.Hello()
(來自實現接口定義)將隱藏SuperClass.Hello()
的SuperClass.Hello()
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.