C# 代码片段文字未正确扩展
C# Code Snippet literal not expanding correctly
我在尝试围绕执行参数检查的简单 Guard class 构建自定义代码片段时遇到了一个奇怪的问题。
后卫Class
public sealed class Guard
{
public static void Null(string paramName, object value)
{
if (value == null) throw new ArgumentNullException(paramName);
}
}
代码片段
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Guard Guid Check</Title>
<Author>Chris Richner</Author>
<Description></Description>
<HelpUrl></HelpUrl>
<SnippetTypes />
<Keywords />
<Shortcut>gg</Shortcut>
</Header>
<Snippet>
<References />
<Imports>
<Import>
<Namespace>Foundation</Namespace>
</Import>
</Imports>
<Declarations>
<Literal Editable="true">
<ID>argument</ID>
<Type>System.Guid</Type>
<ToolTip />
<Default></Default>
<Function />
</Literal>
</Declarations>
<Code Language="csharp" Kind="" Delimiter="$"><![CDATA[Guard.Guid(nameof($argument$), $argument$);$selected$$end$]]></Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
应该生成如下代码
Guard.Null(nameof(arg), arg);
但这不起作用,因为只有第一个参数 $ 文字在 Visual Studio 2015 RTM 代码编辑器中突出显示并最终填充给定的参数名称。
我想念什么?谢谢!
尝试以下方法。
<CodeSnippet Format="1.1.0" xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<Header>
<Title>Guard Guid Check</Title>
<Author>Chris Richner</Author>
<Shortcut>gg</Shortcut>
<Description></Description>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
<SnippetType>SurroundsWith</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>argument</ID>
<ToolTip>Enter argument name</ToolTip>
<Default>argument</Default>
</Literal>
</Declarations>
<Code Language="CSharp"><![CDATA[
Guard.Null(nameof($argument$), $argument$);
]]></Code>
</Snippet>
</CodeSnippet>
查看您的代码,有些地方我不认识。
1) 我不确定 $selected$$end$ 的用途和 2) 我不确定语言 属性 (csharp) 是否区分大小写。
我获取了你的信息并将其放入我知道从 VS 2005 到 VS 2013 都能正常工作的片段中。然后我测试了该片段并且它对我来说工作正常。
我在尝试围绕执行参数检查的简单 Guard class 构建自定义代码片段时遇到了一个奇怪的问题。
后卫Class
public sealed class Guard
{
public static void Null(string paramName, object value)
{
if (value == null) throw new ArgumentNullException(paramName);
}
}
代码片段
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Guard Guid Check</Title>
<Author>Chris Richner</Author>
<Description></Description>
<HelpUrl></HelpUrl>
<SnippetTypes />
<Keywords />
<Shortcut>gg</Shortcut>
</Header>
<Snippet>
<References />
<Imports>
<Import>
<Namespace>Foundation</Namespace>
</Import>
</Imports>
<Declarations>
<Literal Editable="true">
<ID>argument</ID>
<Type>System.Guid</Type>
<ToolTip />
<Default></Default>
<Function />
</Literal>
</Declarations>
<Code Language="csharp" Kind="" Delimiter="$"><![CDATA[Guard.Guid(nameof($argument$), $argument$);$selected$$end$]]></Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
应该生成如下代码
Guard.Null(nameof(arg), arg);
但这不起作用,因为只有第一个参数 $ 文字在 Visual Studio 2015 RTM 代码编辑器中突出显示并最终填充给定的参数名称。
我想念什么?谢谢!
尝试以下方法。
<CodeSnippet Format="1.1.0" xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<Header>
<Title>Guard Guid Check</Title>
<Author>Chris Richner</Author>
<Shortcut>gg</Shortcut>
<Description></Description>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
<SnippetType>SurroundsWith</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>argument</ID>
<ToolTip>Enter argument name</ToolTip>
<Default>argument</Default>
</Literal>
</Declarations>
<Code Language="CSharp"><![CDATA[
Guard.Null(nameof($argument$), $argument$);
]]></Code>
</Snippet>
</CodeSnippet>
查看您的代码,有些地方我不认识。 1) 我不确定 $selected$$end$ 的用途和 2) 我不确定语言 属性 (csharp) 是否区分大小写。
我获取了你的信息并将其放入我知道从 VS 2005 到 VS 2013 都能正常工作的片段中。然后我测试了该片段并且它对我来说工作正常。