【问题标题】:How to create parameters in VS 2010 snippets如何在 VS 2010 代码片段中创建参数
【发布时间】:2012-03-07 01:15:02
【问题描述】:

您好,我想创建一个 Visual Studio sn-p,我可以将预定义的值用于...

例如

<Timeline AutoPlay="$True|FALSE$">

有没有办法做到这一点?

除了 Default 之外,是否还有其他标签可以让我添加可能的值?

    <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>

【问题讨论】:

  • 优秀设计的标志。你可以无休止地想出你想要包括的东西。好的设计是知道要忽略什么。片段是为程序员设计的。
  • 是的,这就是您添加更多功能的原因,实际上没有人需要所有 MS Office 功能,但有些人确实需要...

标签: visual-studio-2010 code-snippets


【解决方案1】:

听起来您想在 Visual Studio 代码段中替换宏。不幸的是,这实际上是不可能的。 Visual Studio sn-ps 只支持极少数的替换宏并且它们不是用户可控的。

【讨论】:

  • 我希望在下拉菜单中设置默认值以外的值。某种辅助代码完成。
  • 有什么办法可以做到吗?
【解决方案2】:

我讨厌这种事发生在我身上,但我们开始吧:

问:如何在 Visual Studio 中做 X?

答:使用ReSharper

在您的情况下为“代码模板”。

【讨论】:

  • 我使用 VA X,因为它是 .我可以在 ReSharper 模板中创建选项列表,还是它的工作方式与 VA 类似?
  • 不是 VA X 用户,所以没有任何线索。这将是一个好的开始:有很好的概述:jetbrains.com/resharper/features/code_templates.html
猜你喜欢
  • 2015-07-06
  • 1970-01-01
  • 1970-01-01
  • 2021-04-28
  • 2021-03-25
  • 2011-07-05
  • 1970-01-01
  • 2021-02-16
  • 2010-10-19
相关资源
最近更新 更多