6

Visual Studio で複数の行を含むコード スニペットを使用する場合、次の行は、元のカーソル位置に対してコードを配置するのではなく、.snippet ファイルで設定された空白を保持します。

foreach スニペットを使用すると、次のようなコードが得られます。

    foreach (var item in collection)
{

}

それ以外の:

    foreach (var item in collection)
    {

    }

この動作を変更する方法はありますか? .snippet ファイルで使用する必要があるキーワードはありますか?

4

2 に答える 2

3

The code portion of a snippet file is contained in a CDATA which preserves whitespace. The best thing I can tell you is to go into the file and edit it to suit your needs. Your only other option is to do a quick Ctrl+K and Ctrl+D after you use the snippet to auto-format the code which will fix the indenting.

于 2009-01-28T16:54:12.740 に答える
1

スニピット ファイルを編集します。

  1. 管理者として、メモ帳などのテキスト エディタを開きます。
  2. 修正するスニペット ファイル (foreach.snippet など) を開きます。(私のコンピューターの C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC#\Snippets\1033\Visual C# にあります)
  3. コード要素の先頭のタブを削除します。Code... xml 要素を次のように変更します。

            <Code Language="csharp"><![CDATA[foreach ($type$ $identifier$ in $collection$)
            {
                $selected$ $end$
            }]]>
            </Code>
    

に:

            <Code Language="csharp"><![CDATA[foreach ($type$ $identifier$ in $collection$)
{
    $selected$ $end$
}]]>
            </Code>
于 2011-03-28T15:30:35.810 に答える