You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何强制IntelliSense为自定义类的指定成员显示星标?

如何给自定义类成员手动添加IntelliSense星标并置顶

要让自定义类RabbitHole的Depth属性和Descend方法在输入currentRabbithole.触发IntelliSense时,像string类的Length、Replace那样显示星标并置顶,可通过添加特性实现,无需依赖系统的使用模式统计:

方法一:使用Visual Studio专属特性(带星标)

此方法依赖Visual Studio的扩展API,能让成员显示星标并置顶:

  1. 引用Microsoft.VisualStudio.Language.Intellisense.dll程序集(通常位于Visual Studio安装目录)。
  2. 给目标成员添加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专属程序集,可通过以下方式让成员置顶:

  1. 给目标成员添加EditorBrowsable(EditorBrowsableState.Always)特性(显式标记为始终显示)。
  2. 确保Visual Studio设置开启「显示常用成员」:
    • 路径:工具 → 选项 → 文本编辑器 → C# → IntelliSense → 勾选「显示常用成员」。

此方案下成员会优先显示,但不会带有星标。

内容的提问来源于stack exchange,提问作者Greg

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.23 17:43:09