折叠区域中的代码片段

发布于 2024-09-24 06:52:49 字数 963 浏览 1 评论 0原文

我正在尝试添加代码片段,并且希望此代码出现在某个区域中。所以我在片段文件中尝试了类似的操作。

<CodeSnippets
    xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <Title>
        rg
        Code Snippet for Region
      </Title>
      <Shortcut>rg</Shortcut>
    </Header>
    <Snippet>
      <References>
        <Reference>
          <Assembly>System.dll</Assembly>
        </Reference>
      </References>
      <Code Language="CSharp">
        <![CDATA[
        #region MyRegion
        // Some Code
        #endregion
        ]]>
      </Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>

但是当我使用代码片段 rg 时,该区域默认显示为展开的,如下所示。

 - #region MyRegion
    // Some Code
    #endregion

有什么办法可以让这个区域像这样默认折叠吗?

 + MyRegion

I am trying to add a code snippet and I want this code to appear in a region. So I tried something like this in the snippet file.

<CodeSnippets
    xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <Title>
        rg
        Code Snippet for Region
      </Title>
      <Shortcut>rg</Shortcut>
    </Header>
    <Snippet>
      <References>
        <Reference>
          <Assembly>System.dll</Assembly>
        </Reference>
      </References>
      <Code Language="CSharp">
        <![CDATA[
        #region MyRegion
        // Some Code
        #endregion
        ]]>
      </Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>

But when I use the code snippet rg, the region appears as expanded by default like this.

 - #region MyRegion
    // Some Code
    #endregion

Is there any way I can get this region as collapsed by default like this?

 + MyRegion

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

南薇 2024-10-01 06:52:49

据我所知,插入 sippet 操作被视为正常的复制和粘贴操作。因此,我认为不可能插入折叠区域。特别是,VS 需要一些时间才能将其识别为一个区域。

As far as I know, the insert sippet operation is treated like a normal copy and paste operation. Therefore, I would assume that it is not possible to insert a collapsed region. Especially, as it takes VS some time to recognize it as a region.

摘星┃星的人 2024-10-01 06:52:49
<![CDATA[
#region $RegionName$
$selected$ $end$
#endregion
]]>

你可以尝试一下这个方法,看看是否有效。

http://www.mikebevers.be /blog/2009/06/visual-studio-custom-region-code-snippet/

<![CDATA[
#region $RegionName$
$selected$ $end$
#endregion
]]>

You can try this and see if it works.

http://www.mikebevers.be/blog/2009/06/visual-studio-custom-region-code-snippet/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文