Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 代码段在VS2015中插入额外的换行符_C#_Visual Studio_Visual Studio 2015_Code Snippets - Fatal编程技术网

C# 代码段在VS2015中插入额外的换行符

C# 代码段在VS2015中插入额外的换行符,c#,visual-studio,visual-studio-2015,code-snippets,C#,Visual Studio,Visual Studio 2015,Code Snippets,我已经制作了一个自定义代码段,供VisualStudio使用。在VS2013中,它按预期工作,但自从在VS2015(社区版)中使用它以来,它一直在代码前插入一个额外的换行符(就在我第二次按tab/enter时) 这似乎只是自定义代码段的问题(内置代码段工作正常)。有人知道这是什么原因吗?这很烦人 作为旁注,只有在激活空代码行上的代码段时才会发生这种情况。如果在现有代码之后执行此操作,则不会插入换行符。不幸的是,这个片段是一个语句,所以这没有多大帮助 以下是几乎完全从VS示例复制的代码片段: &l

我已经制作了一个自定义代码段,供VisualStudio使用。在VS2013中,它按预期工作,但自从在VS2015(社区版)中使用它以来,它一直在代码前插入一个额外的换行符(就在我第二次按tab/enter时)

这似乎只是自定义代码段的问题(内置代码段工作正常)。有人知道这是什么原因吗?这很烦人

作为旁注,只有在激活空代码行上的代码段时才会发生这种情况。如果在现有代码之后执行此操作,则不会插入换行符。不幸的是,这个片段是一个语句,所以这没有多大帮助

以下是几乎完全从VS示例复制的代码片段:

<?xml version="1.0" encoding="utf-8" ?> 
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/CodeSnippet">
<CodeSnippet Format="1.0.0">

    <!-- The header contains information describing the snippet. -->
    <Header>

      <!-- The Title of the snippet, this will be shown in the snippets manager. -->
      <Title>Insert Field Add</Title>

      <!-- The description of the snippet. -->
      <Description>Inserts a basic field add for a DataObject</Description>

      <!-- The author of the snippet. -->
      <Author>Thomas Price</Author>

      <!-- The set of characters that must be keyed in to insert the snippet. -->
      <Shortcut>fadd</Shortcut>

      <!-- The set of snippet types we're dealing with - either Expansion or -->
      <SnippetTypes>
        <SnippetType>Expansion</SnippetType>
      </SnippetTypes>          

    </Header>

    <!-- Now we have the snippet itself. -->
    <Snippet>
        <!-- Create any declarations that we use in the snippet. -->
        <Declarations>
          <Literal>
            <ID>FieldName</ID>
            <ToolTip>Enter the field name</ToolTip>
            <Default>field</Default>
          </Literal>
        </Declarations>

        <!-- Sepecify the code language and the actual snippet content. -->
        <Code Language="CSharp" Kind="any">
            <![CDATA[$FieldName$ = fields.add($FieldName$, "$FieldName$");]]>
        </Code>
    </Snippet>
</CodeSnippet>

插入字段添加
插入数据对象的基本字段add
白梓轩
法德
膨胀
字段名
输入字段名
领域



您可以通过在代码段文本中的某个位置放置$end$来防止前面的换行。例如:

<![CDATA[$FieldName$ = fields.add($FieldName$, "$FieldName$");$end$]]>


也有一个
$start$
吗?下面是答案。“在
code
元素的文本中只有两个保留字可用:
$end$
$selected$
”@ciwan这似乎很明显,但要使其起作用,您不能在
CDATA之后添加新行[
括号,也就是说,你必须在它之后立即开始你的代码段。我有一个多行代码段,在它上面,在
CDATA[
之后很自然地需要一个换行符,而且因为我以前尝试过删除没有任何效果的换行符,所以我花了一点时间才意识到你需要这两个东西(
$end$
并且没有换行符)。这是因为在插入代码段后告诉VS它应该将光标放置在何处,可以防止光标出现在插入的代码之前。VS2019也有同样的问题。在末尾添加
$end$
对我有效。可能重复