Explicit interface implementation is shown as 'private' in File Structure

I noticed that an explicit interface implementation is shown as 'private' (small lock on icon) in File Structure window. Possibly, R# mistakenly recognizes it as 'private' because there is no 'public' keyword in method's header. But an explicit interface implementation is public by default, so compiler doesn't require (and really doesn't allow) 'public' keyword in it. So, it's a bug, isn't it?

OS Name: Microsoft Windows XP Professional
OS Version: 5.1.2600 Service Pack 2 Build 2600
VS 2005 version 8.0.50727.51
R# build 251



Attachment(s):
private.GIF
4 comments
Comment actions Permalink

It is private

--
Eugene Pasynkov
Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
"Vladimir Reshetnikov" <no_reply@jetbrains.com> wrote in message
news:29582385.1150718026825.JavaMail.itn@is.intellij.net...
>I noticed that an explicit interface implementation is shown as 'private'
>(small lock on icon) in File Structure window. Possibly, R# mistakenly
>recognizes it as 'private' because there is no 'public' keyword in method's
>header. But an explicit interface implementation is public by default, so
>compiler doesn't require (and really doesn't allow) 'public' keyword in it.
>So, it's a bug, isn't it?
>

OS Name: Microsoft Windows XP Professional
OS Version: 5.1.2600 Service Pack 2 Build 2600
VS 2005 version 8.0.50727.51
R# build 251



0
Comment actions Permalink

Here is detailed example (see attachments). You may invoke Eat method from another class so it's public. If you uncomment 'public' keyword it will be highlighted as an error ("The modifier 'public' is not valid for explicit interface implementation") and compilation will fail. But the method will be shown as 'public' in File Structure window (no small lock).

using System;

public interface IFruit
{
void Eat();
}

public class Apple : IFruit
{
/* public */ void IFruit.Eat()
{
throw new NotImplementedException();
}
}

public class Boy
{
public void EatApple()
{
IFruit fruit = new Apple();
fruit.Eat();
}
}



Attachment(s):
1.cs
2.cs
2.gif
1.gif
0
Comment actions Permalink

Vladimir,

The question whether to regard explicit implementations as public or private
is a matter of taste. They can be believed to be public, private, or neither.
We prefer to display them 'private'-like because outside of the container
class you know nothing of them. For example, in the code fragment you cannot
invoke Eat() method through an instance of class Apple. (Similar reasons
allow us to regard interface members as public - they are visible outside
the interface they are declared in.)

Thanks,
Andrey Simanovsky


0
Comment actions Permalink

Andrey, thanks. You are quite right.

"...an explicitly implemented member is publicly callable even though its signature is private. Because of this, explicitly implemented members do not appear in the list of publicly visible members." (MSDN)

0

Please sign in to leave a comment.