可以防止方法出现在智能感知中吗?

时间:2010-07-15 14:31:20

标签: .net visual-studio intellisense

假设我有一个课程,我想弃用一个方法。是否有可能让这种方法不会出现在intellisense中,这样人们就不会习惯使用它?我只想要使用它的现有代码继续编译,但同时从视图中隐藏方法。

2 个答案:

答案 0 :(得分:12)

EditorBrowsableAttribute属性可用于隐藏intellisense中的成员:

http://msdn.microsoft.com/en-us/library/system.componentmodel.editorbrowsableattribute.aspx

答案 1 :(得分:8)

或者,您可以使用System.ObsoleteAttribute。将方法显示在intellisense中仍然是一个好主意,因为从技术上讲它是存在的。

使用此属性将在智能感知中显示方法名称,但前面带有[deprecated]标记。

[Obsolete("Method is in the process of deprecation.")]
void MyMethod() {...}

如果您使用ReSharper,并告诉它覆盖Visual Studio的Intellisense设置,它将覆盖方法名称。