C # - Cannot find method use when inheriting and using via interface implemented by subclass

I use VisualStudio 2008 and 2010, both with ReSharper, and when I try to look for ways to use this method, I do not get any results, despite the inherited method, and then it is called through the interface. What's wrong? Is this a VS / ReSharper error? 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

+6
source share
3 answers

This is a known issue: http://youtrack.jetbrains.net/issue/RSRP-46273 without the current target fix version

+1
source

Perhaps because your SuperClass does not implement an interface. This may cause a problem for ReSharper. Try:

  class SuperClass : MyInterface { public void Hello() { Console.WriteLine("Hi!"); } } 
+1
source

This is all due to the order in which SubClass inherits the Hello() method from SuperClass and MyInterface .

I am surprised that you will not receive a warning that SubClass.Hello() (from the implementation of the interface definition) will hide SuperClass.Hello() .

0
source

Source: https://habr.com/ru/post/900434/


All Articles