如何强制IntelliSense为自定义类的指定成员显示星标?
如何给自定义类成员手动添加IntelliSense星标并置顶
要让自定义类RabbitHole的Depth属性和Descend方法在输入currentRabbithole.触发IntelliSense时,像string类的Length、Replace那样显示星标并置顶,可通过添加特性实现,无需依赖系统的使用模式统计:
方法一:使用Visual Studio专属特性(带星标)
此方法依赖Visual Studio的扩展API,能让成员显示星标并置顶:
- 引用
Microsoft.VisualStudio.Language.Intellisense.dll程序集(通常位于Visual Studio安装目录)。 - 给目标成员添加
PriorityItemAttribute和EditorBrowsableAttribute:
using System.ComponentModel; using Microsoft.VisualStudio.Language.Intellisense; public class RabbitHole { public double Width; [PriorityItem(PriorityItemKind.Common)] [EditorBrowsable(EditorBrowsableState.Always)] public double Depth; [PriorityItem(PriorityItemKind.Common)] [EditorBrowsable(EditorBrowsableState.Always)] public void Descend(double toDepth) { // ... } public void Ascend(double toHeight) { // ... } }
方法二:通用方案(置顶无星标)
如果不想依赖Visual Studio专属程序集,可通过以下方式让成员置顶:
- 给目标成员添加
EditorBrowsable(EditorBrowsableState.Always)特性(显式标记为始终显示)。 - 确保Visual Studio设置开启「显示常用成员」:
- 路径:工具 → 选项 → 文本编辑器 → C# → IntelliSense → 勾选「显示常用成员」。
此方案下成员会优先显示,但不会带有星标。
内容的提问来源于stack exchange,提问作者Greg
相关产品推荐
相关产品推荐

