0

这个链接之后,我有一组代码片段。

但是片段插入必须与上下文有关,即。如果我在声明类之前执行“插入片段”,则不应显示“方法声明”片段。还需要根据托管或非托管代码过滤片段。

简而言之,我正在寻找一种机制如下:

if <condition>
{
 modify list of snippets visible in the menu
}

我们有这样的机制或类似的东西吗?欢迎提出想法。

4

1 回答 1

0

我找到了我的问题的解决方案。希望它可以帮助某人。

我按照链接上的说明进行操作: 关于代码片段代码元素的视频

让 snippet.xml 文件包含以下内容:

<Code Language="Language"
    Kind="method decl">
        Code to insert
</Code>

然后调用FilterView类中的expansionProvider.DisplayExpansionBrowser(参考视频):

string[] kind = new string[1];                            
kind[0] = "method decl";
return expansionProvider.DisplayExpansionBrowser(TextView, 
                                                 snippets, 
                                                 null, false, kind, false);

Thus the specific snippet will appear in 'method declaration' context. Thus other snippets can be done. The xml has to hold the context information.

于 2012-09-17T15:49:59.467 回答