如何在Visual Studio中更改道具快捷方式的默认行为

Nam*_*man 2 c# visual-studio

当我们使用prop快捷方式生成属性时,它会将其生成为int.但是,在大多数情况下,我使用字符串属性.有什么办法可以更改此快捷方式的默认行为来生成字符串属性吗?

Nko*_*osi 8

我为自定义行为编写了自己的代码片段.喜欢props串等

如果您Code Snippet Manager在Visual Studio中打开它,它将显示片段文件的位置,该文​​件是可编辑的.如果您使用VS,则位置因版本而异.

在VS2013上,它prop为c#显示了以下路径

C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC#\Snippets\1033\Visual C#/prop.snippet

然后我可以打开它一个文本编辑器并根据需要自定义文件.

<?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>string</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>
Run Code Online (Sandbox Code Playgroud)

请注意以上内容如何更改string为默认类型