如何从智能感知隐藏公共方法

我想隐藏intellisense成员列表中的公共方法。 我创build了一个属性,当应用于一个方法将导致该方法被调用时,其对象的构造。 我已经做了这个更好的支持部分类。 问题是,在某些环境(如Silverlight)中,reflection不能访问私有成员,即使是那些子类。 这是一个问题,因为所有的工作都是在基类中完成的。 我必须公开这些方法,但是我希望它们对于智能感知是隐藏的,类似于Obsolete属性的工作方式。 坦率地说,因为我是关于对象封装的肛门。 我尝试了不同的东西,但没有任何实际工作。 该方法仍显示在成员下拉菜单中。

如果我不希望他们被客户打电话,我怎样才能让公开的方法在智能感知中出现?真是个问题,非利士人呢! 这也可以适用于必须公开的MEF属性,虽然有时候你想把它们隐藏起来。

更新:自从我发布这个问题以来,我已经成熟了。 为什么我关心隐藏界面是超越我的。

展开我对部分方法的评论。 尝试这样的事情

Foo.part1.cs

 partial class Foo { public Foo() { Initialize(); } partial void Initialize(); } 

Foo.part2.cs

 partial class Foo { partial void Initialize() { InitializePart1(); InitializePart2(); InitializePart3(); } private void InitializePart1() { //logic goes here } private void InitializePart2() { //logic goes here } private void InitializePart3() { //logic goes here } } 

像这样使用EditorBrowsable属性会导致方法不能在智能感知中显示:

 [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] public void MyMethod() { } 

您正在寻找EditorBrowsableAttribute

以下示例演示如何通过为EditorBrowsableAttribute属性设置适当的值来隐藏IntelliSense中类的属性。 在自己的程序集中构buildClass1。

在Visual Studio中,创build一个新的Windows应用程序解决scheme,并添加对包含Class1的程序集的引用。 在Form1构造函数中,声明Class1的实例,键入实例的名称,然后按周期键以激活Class1成员的IntelliSense下拉列表。 Age属性不会出现在下拉列表中。

 using System; using System.ComponentModel; namespace EditorBrowsableDemo { public class Class1 { public Class1() { // // TODO: Add constructor logic here // } int ageval; [EditorBrowsable(EditorBrowsableState.Never)] public int Age { get { return ageval; } set { if (!ageval.Equals(value)) { ageval = value; } } } } }