如何从 IntelliSense 中隐藏公共方法
我想从 IntelliSense 成员列表中隐藏公共方法。我创建了一个属性,当将该属性应用于方法时,将导致在构造其对象时调用该方法。我这样做是为了更好地支持部分类。问题在于,在某些环境(例如 Silverlight)中,反射无法访问私有成员,甚至是子类的私有成员。这是一个问题,因为所有工作都是在基类中完成的。我必须公开这些方法,但我希望它们对 IntelliSense 隐藏,类似于 Obsolete
属性的工作方式。坦率地说,因为我对对象封装很感兴趣。我尝试过不同的方法,但实际上没有任何效果。该方法仍然显示在成员下拉列表中。
当我不希望客户端调用公共方法时,如何防止公共方法出现在 IntelliSense 中?这是一个真正的问题,非利士人!这也适用于必须公开的 MEF 属性,尽管有时您希望对客户端隐藏它们。
更新: 自从我发布这个问题以来,我作为一名开发人员已经成熟了。我不明白为什么我如此关心隐藏界面。
I want to hide public methods from the IntelliSense member list. I have created an attribute that, when applied to a method, will cause the method to be called when its object is constructed. I've done this to better support partial classes. The problem is that in some environments (such as Silverlight), reflection cannot access private members, even those of child classes. This is a problem since all of the work is done in a base class. I have to make these methods public, but I want them to be hidden from IntelliSense, similar to how the Obsolete
attribute works. Frankly, because I am anal about object encapsulation. I've tried different things, but nothing has actually worked. The method still shows up in the member drop-down.
How do I keep public methods from showing up in IntelliSense when I don't want them to be called by clients? How's that for a real question, Philistines! This can also apply to MEF properties that have to be public though sometimes you want to hide them from clients.
Update:
I have matured as a developer since I posted this question. Why I cared so much about hiding interface is beyond me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用
EditorBrowsable
属性像这样会导致方法不显示在 IntelliSense 中:Using the
EditorBrowsable
attribute like so will cause a method not to be shown in IntelliSense:您正在寻找
EditorBrowsableAttribute
You are looking for
EditorBrowsableAttribute
扩展我对部分方法的评论。尝试这样的东西
Foo.part1.cs
Foo.part2.cs
To expand on my comment about partial methods. Try something like this
Foo.part1.cs
Foo.part2.cs