'Incorrectly' highlighted as unused
We have some C# code where Resharper is incorrectly (albeit understandably) indicating that methods are unused when they aren't.
The methods are declared as private then accessed from the base class using dynamic casting:
Declaration (derived class):

Usage (base class):

Whilst I wouldn't consider this a bug it is a potential problem as it could lead to methods being removed during a refactor/analysis phase by a careless programmer. Is there anything we can do (other than making the methods public) to stop this? Ideally we'd like to put something on the base class so that the 'behaviour' is inherited.
Thanks.
Please sign in to leave a comment.
You could try adding a [UsedImplicitly] annotation to the methods, or a [UsedImplicitly(ImplicitUseTargetFlags.WithMembers)] annotation to the base class.
Annotations in Source Code - Help | ReSharper
Hey, thanks for that, good to know and it will certainly help. Unfortunately that won't help with the base class because it doesn't declare Apply. It's a bit weird but the descendants implement multiple Apply() methods so we're doing a kind of runtime version of compile time binding.
So to extend my first post that descendant also has:
The base class can't declare multiple methods (they'd have the same signature (IMediaCommand, IWorker) and it doesn't know what descendants will implement. Hence the use of dynamic.