Reputation: 33
I have an interface and it has many methods. I should not see these methods in Intellisense in implementing classes. How can I do that?
Upvotes: 3
Views: 1651
Reputation: 21742
You will need to implement them explicitly.
If your interface is:
interface IFoo{
void DoSomething();
}
then you can implement that explicitly in a class like below:
class Foo : IFoo {
void IFoo.DoSomething();
}
That being said, you probably wonder consider why you want to do this. An interface is often used to define a contract of what an object of a given type is capable of. Wanting to hide it can be a smell of something go astray in the design process. Of course there's also many valid cases for the use of explicit implementation. E.g. Dictionary has explicit implementations for quite a few of the methods from IEnumerable>. but the hiding should be more the exception than the rule.
If you declare the variable/member of the interface type the methods will show, if you declare the member/variable of the concrete type they will not show. Since you should generally prefere interfaces to concrete classes this again is a hint that you might wanna look at the reason for wanting to hide the methods declared by the interface
Upvotes: 5
Reputation: 24403
You can use EditorBrowsableAttribute on your methods.
EditorBrowsableAttribute Specifies that a property or method is viewable in an editor. EditorBrowsableAttribute is a hint to a designer indicating whether a property or method is to be displayed. You can use this type in a visual designer or text editor to determine what is visible to the user. For example, the IntelliSense engine in Visual Studio uses this attribute to determine whether to show a property or method.
Something like
[EditorBrowsable(EditorBrowsableState.Never)]
public void GetId()
{
}
Upvotes: 7