tags:

views:

227

answers:

3

I love resharper.

However, I have the following problem:

My naming convention for private methods is camel.

So for so good.

However, when I implement an interface method explicitely as in

void IMyInterface.MyMethod (...)

resharper treats it as a private method and wants to change it to IMyInterface.myMethod. Is there a way to ignore naming convention for explicit interface implementations?

A: 

That will not work.

Resharper is using the name provided by the interface itself - and in order to implement it, you cannot change this name (even casing).

"MyMethod" is the name as specified in "IMyInterface". You must preserve the casing in order to implement that method, and since you're explicitly implementing it, there are no options.


Edit after comments:

Here is an example. I just made an interface, like so:

internal interface IMyInterface
{
    void testmethod();
}

This violates my current naming conventions (Resharper asks to capitalize testmethod in this case).

If I then make a class that implements this interface:

class MyClass : IMyInterface
{

And I choose to "Implement Interface Explicitly", Resharper creates:

class MyClass : IMyInterface
{
    #region IMyInterface Members

    void IMyInterface.testmethod()
    {
        throw new NotImplementedException();
    }

    #endregion
}

In this case, it does not complain about the casing in the line: void IMyInterface.testmethod()

There would be no way to implement the interface using a different casing than the one in the interface, however - that doesn't matter whether it's explicitly or implicitly defined - the interface determines the name of the method, including the case.

I think the confusion may be due to the fact that you're assuming that, in my case, testmethod is private - it is not a private method, it's a public, explicit implementation of IMyInterface.testmethod, which is why you can do:

IMyInterface myClass = new MyClass();
myClass.testmethod(); // This is public on IMyInterface, not private!

You cannot change the case of the method implementing your interface - this is a .NET restriction, not a Resharper restriction.

Reed Copsey
But it seems Resharper ignores this and happily changes the case of implicitly implemented methods because it treats them as private methods. I think the question is, how to prevent Resharper from doing this, instead of how to make it do it.
dtb
Oh, if that's the case, then it's a matter of leaving off the modifier "private". I believe Resharper (from my testing just now) is smart enough to not change the case of an explicitly implemented interface, though.
Reed Copsey
Curious as to why the downvote - I just tested this again, right now, and resharper WILL let you implement an interface explicitly that violates your rules.
Reed Copsey
Just added full, detailed explanation of this, including testing in a new project with resharper.
Reed Copsey
Thanks for your time. However, it does not answer my question. I don't wont to change my method name to testMethod. I want resharper to stop complaining.
tom greene
A: 

Interface methods are not allowed to be private. When explicitly using the interface, you'll use

void IMyInterface.MyMethod(...)

without an accessibility setting. The implementation will be public or internal depending of if the interface is public or internal.

Jarrett Meyer
A: 

There was a bug in some versions of ReSharper, and it was fixed long ago. What version do you use? Did you try latest builds, like 4.5.1 or one of the latest nightlies?

Ilya Ryzhenkov
I am using resharper 4.5. Is it too old?
tom greene