如何在 VS 2010 代码片段中创建参数
您好,我想创建一个 Visual Studio 代码片段,我可以将其预定义值...
例如,
<Timeline AutoPlay="$True|FALSE$">
有没有办法做到这一点?
除了默认值之外,还有其他标签可以让我添加可能的值吗?
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/CodeSnippet">
<CodeSnippet>
<Header>
<!-- Add Header information here -->
</Header>
<Snippet>
<!-- Add additional Snippet information here -->
<Declarations>
<Literal>
<ID>SqlConnString</ID>
<ToolTip>Replace with a SQL connection string.</ToolTip>
**<Value>"Value1"</Value>
<Value>"Value2"</Value>**
<Default>"SQL connection string"</Default>
</Literal>
<Object>
<ID>SqlConnection</ID>
<Type>System.Data.SqlClient.SqlConnection</Type>
<ToolTip>Replace with a connection object in your application.</ToolTip>
<Default>dcConnection</Default>
</Object>
</Declarations>
<Code Language="CSharp">
<![CDATA[
daCustomers = new SqlClient.SqlDataAdapter();
selectCommand = new SqlClient.SqlCommand($SqlConnString$);
daCustomers.SelectCommand = selectCommand;
daCustomers.SelectCommand.Connection = $SqlConnection$;
]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
Hi I would like to create a Visual Studio snippet that I can have predefined values to...
for instance
<Timeline AutoPlay="$True|FALSE$">
Is there a way to do this?
Is there a tag other than Default that will allow me to add possible values?
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/CodeSnippet">
<CodeSnippet>
<Header>
<!-- Add Header information here -->
</Header>
<Snippet>
<!-- Add additional Snippet information here -->
<Declarations>
<Literal>
<ID>SqlConnString</ID>
<ToolTip>Replace with a SQL connection string.</ToolTip>
**<Value>"Value1"</Value>
<Value>"Value2"</Value>**
<Default>"SQL connection string"</Default>
</Literal>
<Object>
<ID>SqlConnection</ID>
<Type>System.Data.SqlClient.SqlConnection</Type>
<ToolTip>Replace with a connection object in your application.</ToolTip>
<Default>dcConnection</Default>
</Object>
</Declarations>
<Code Language="CSharp">
<![CDATA[
daCustomers = new SqlClient.SqlDataAdapter();
selectCommand = new SqlClient.SqlCommand($SqlConnString$);
daCustomers.SelectCommand = selectCommand;
daCustomers.SelectCommand.Connection = $SqlConnection$;
]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
听起来您想在 Visual Studio Snippet 中替换宏。不幸的是,这实际上是不可能的。 Visual Studio 代码片段仅支持极少量的替换宏,并且用户无法控制它们。
It sounds like you want macro replacement in a Visual Studio Snippet. Unfortunately this is not really possible. Visual Studio snippets only support a very small number of replacement macros and they are not user controllable.
我讨厌这种事发生在我身上,但我们开始吧:
问:如何在 Visual Studio 中执行 X?
答:使用 ReSharper。
在你的情况下是“代码模板”。
I hate when it happens to me, but here we go:
Q: How do I do X in Visual Studio?
A: Use ReSharper.
in your case "Code Templates".