【问题标题】:Using shortcuts in visual studio 2013在 Visual Studio 2013 中使用快捷方式
【发布时间】:2015-07-24 14:43:35
【问题描述】:

使用以下内容并按 Tab 键 Visual Studio 为我们编写属性。

//prop
public int MyProperty { get; set; }
//propg
public int MyProperty { get; private set; }
//propfull
private int myVar;

public int MyProperty
{
    get { return myVar; }
    set { myVar = value; }
}

如你所见,默认情况下它们都是 int 有没有办法更改快捷方式以允许不同的数据类型

【问题讨论】:

    标签: c# visual-studio


    【解决方案1】:

    我使用 Visual Studio 2012 和我的所有 C# 代码 sn-ps

    C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC#\Snippets\1033\Visual C#\

    文件夹。例如,当你编辑prop.snippet时,你会得到like;

    <?xml version="1.0" encoding="utf-8" ?>
    <CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
        <CodeSnippet Format="1.0.0">
            <Header>
                <Title>prop</Title>
                <Shortcut>prop</Shortcut>
                <Description>Code snippet for an automatically implemented property
    Language Version: C# 3.0 or higher</Description>
                <Author>Microsoft Corporation</Author>
                <SnippetTypes>
                    <SnippetType>Expansion</SnippetType>
                </SnippetTypes>
            </Header>
            <Snippet>
                <Declarations>
                    <Literal>
                        <ID>type</ID>
                        <ToolTip>Property type</ToolTip>
                        <Default>int</Default>
                    </Literal>
                    <Literal>
                        <ID>property</ID>
                        <ToolTip>Property name</ToolTip>
                        <Default>MyProperty</Default>
                    </Literal>
                </Declarations>
                <Code Language="csharp"><![CDATA[public $type$ $property$ { get; set; }$end$]]>
                </Code>
            </Snippet>
        </CodeSnippet>
    </CodeSnippets>
    

    如您所见,它默认定义为&lt;Default&gt;int&lt;/Default&gt;。您可以根据需要更改它的类型。

    您也可以在Code Snippet Manager 中找到它们;

    【讨论】:

    • 感谢您的回答。我可以添加多个数据类型还是不可能?
    • @Code 我认为使用多种数据类型是不可能的。即使有可能,编译器如何知道它选择了哪种类型?
    • 是的,确实如此。谢谢您的帮助
    猜你喜欢
    • 2014-09-26
    • 1970-01-01
    • 2014-01-12
    • 2014-07-26
    • 2014-02-28
    • 1970-01-01
    • 2010-09-06
    • 1970-01-01
    • 2021-12-15
    相关资源
    最近更新 更多