Is this a Find Usage bug?

I recently came across a particularly convoluted bit of code - but it is valid C# and it does compile.  Basically, when I'm on the highlighted line and do a Find Usages on the ProvideFoo method, ReSharper tells me nothing is using it.

Here's the code - the names have been changed to protect the guilty!

    public interface IProvideFoos

    {
        IFoo ProvideFoo( ) ;
    }

    public class BaseWhatever
    {
        public IFoo ProvideFoo( ) // Find Usages here results in nothing
        {
            throw new NotImplementedException( ) ;
        }
    }

    public class RealWhatever : BaseWhatever, IProvideFoos
    {

    }

    public static class ServiceMother
    {
        public static IProvideFoos FooProvider
        {
            get
            {
                return new RealWhatever( ) ;
            }
        }
    }

    public class MyApp
    {
        public MyApp( )
        {
            IProvideFoos fooProvider = ServiceMother.FooProvider ;
            IFoo foo = fooProvider.ProvideFoo( ) ;
        }
    }


The problem is - ServiceMother returns a RealWhatever but dressed in an IProvideFoos interface.  RealWhatever does derive from IProvideFoos, but the implementation is inferred from the BaseWhatever type.

Do you think R# should show the usages?  Should it go through an analyse the FooProvider property of ServiceMother and realise that it returns a RealWhatever that is later used to call the ProvideFoos method?

Cheers,

Steve

1 comment

Hello,

Rather an optimization, I think. Here you're looking for usages of an quasi-implementation
method called through that interface. Public methods that are regular implementations
will have the same result, but in that case you're asked whether to look
for the interface usages also. In the quasi-implementation case, there's
currently no way of checking quickly whether the method is a quasi-implementation
or not, so the choice is not offered.

Here're a few requests on the topic:
http://youtrack.jetbrains.net/issue/RSRP-46273
http://youtrack.jetbrains.net/issue/RSRP-143767


Serge Baltic
JetBrains, Inc — http://www.jetbrains.com
“Develop with pleasure!”


0

Please sign in to leave a comment.