Visual Studio keyboard short-cut to complete default accessors {get; set;}

瘦欲@ 提交于 2019-12-03 08:12:56

问题


I am looking for a keyboard short-cut to complete creating the default accessors for a property in a C# class.

Something like...
I start typing:

public int Id 

Then I press one or more keys, and I endup with:

public int Id { get; set; }

回答1:


The shortcut is the trigger "prop":

proptabtabinttabIdtab

and you end up with:

public int Id { get; set; }



回答2:


Try with propfull , then TAB Twice and you'll get:

private int myVar;

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



回答3:


You could also create a custom snippet:

<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>GetSet</Title>
            <Description>Inserts getter/setter shorthand code</Description>
            <Shortcut>gs</Shortcut>
        </Header>
        <Snippet>
            <Code Language="CSharp">
                <![CDATA[{ get; set; }$end$]]>
            </Code>
        </Snippet>
    </CodeSnippet>
</CodeSnippets>



回答4:


The shortcut is using CTRL+R and then CTRL+E. Press these keys after writing:

int loginID;

Then you will get the following encapsulation:

    int loginID;

    public int LoginID
    {
        get { return loginID; }
        set { loginID = value; }
    }


来源:https://stackoverflow.com/questions/2936550/visual-studio-keyboard-short-cut-to-complete-default-accessors-get-set

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!