Visual Studio에서 생성자를 만드는 코드 조각 또는 바로 가기
Visual Studio에서 생성자를 만드는 코드 조각 또는 바로 가기는 무엇입니까?
Visual Studio 2010 및 C #
전에 사용해 봤지만 기억이 나지 않습니다.
"ctor"+ TAB+를 입력 TAB하십시오 (Tab 키를 두 번 누르십시오). 이렇게하면 현재 클래스의 기본 생성자가 생성됩니다.
public MyClass()
{
}
어떤 경우에는 TAB두 번 눌러야 할 것 같습니다 .
사용 가능한 모든 스 니펫 목록을 보려면 :
Ctrl+ K를 누른 다음을 누릅니다 X.
을 입력 ctor
한 다음을 TAB두 번 누릅니다 .
스 니펫 (조립식 코드의 작은 비트)의 전체 목록을 보려면 Ctrl+ K를 누른 다음 Ctrl+를 누릅니다 X. MSDN의 출처 . Visual Studio 2013에서 C # 프로젝트와 함께 작동합니다.
생성자를 만드는 방법
- 를 눌러 Ctrl+ K후 Ctrl+X
- Visual C #을 선택하십시오.
- ctor를 선택하십시오
- 프레스 Tab
업데이트 : 코드에서 원하는 부분을 마우스 오른쪽 버튼으로 클릭하고 마우스 오른쪽 버튼 클릭 메뉴에서 코드 조각 삽입을 선택할 수도 있습니다
Visual Studio 2010에서 "ctor"(따옴표없이)를 입력하면 IntelliSense가로드되고 목록에 "ctor"가 표시됩니다. 이제 TAB두 번 누르면 빈 생성자가 생성되어야합니다.
간단히 입력 ctor
한 다음을 누릅니다 TAB.
ctor를 입력 한 다음 Tab키를 누릅니다.
ctor
및을 입력하십시오 Tab.
َََََََََََ
Visual Studio 2010에 대해 잘 모르지만 Visual Studio 2008에서 코드 조각은 'ctor'입니다.
코드 스 니펫의 이름을 입력하고을 누릅니다 TAB.
속성에 대한 코드를 얻으려면 TABVisual Studio에 'prop', 'propa'및 'propdp'와 같은 'prop'로 시작하는 옵션이 둘 이상 있으므로 올바른 옵션을 선택하고 두 번 눌러야 합니다.
'ctor'또는 유사한 클래스 이름 주입 스 니펫을 처음부터 작성하려면 C:\VS2017\VC#\Snippets\1033\Visual C#\C#Snippets.snippet
다음 XML 컨텐츠 를 사용하여 C # 스 니펫 디렉토리에 .snippet 파일을 작성하십시오 (예 :) .
<CodeSnippets>
<CodeSnippet>
<Header>
<Title>ctor</Title>
<Shortcut>ctor</Shortcut>
</Header>
<Snippet>
<Declarations>
<Literal Editable="false"><ID>classname</ID><Function>ClassName()</Function></Literal>
</Declarations>
<Code>
<![CDATA[public $classname$($end$)
{
}]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
이 스 니펫은 이 docs.microsoft 페이지 에 자세히 설명 된 C # 코드 스 니펫 함수 ClassName ()을 호출하여 현재 클래스 이름을 삽입합니다 .
이 코드 스 니펫을 확장 한 최종 결과 :
Visual Studio 2017의 경우 "Ctrl +."를 누르십시오.
As mentioned by many "ctor" and double TAB works in Visual Studio 2017 but it only creates the constructor with none of the attributes.
To auto-generate with attributes (if there are any), just click on an empty line below them and press CTRL+.. It'll display a small pop-up from which you can select the "Generate Constructor..." option.
In case you want a constructor with properties you need to do following:
- Place your cursor in any empty line in a class;
- Press
Ctrl+.
to trigger the Quick Actions and Refactorings menu; - Select Generate constructor from the drop-down menu;
- Pick the members you want to include as constructor parameters. You can order them using the up and down arrows. Choose OK.
The constructor is created with the specified parameters.
Generate a constructor in Visual Studio
I have created some handy code snippets that'll create overloaded constructors as well. You're welcome to use them: https://github.com/ejbeaty/Power-Snippets
For example: 'ctor2' would create a constructor with two arguments and allow you to tab through them one by one like this:
public MyClass(ArgType argName, ArgType argName)
{
}
if you use ReSharper, you can quickly generate constructors by typing 'ctor' + Tab + Tab
(without parameters), 'ctorf' + Tab + Tab
(with parameters that initialize all fields) or 'ctorp' + Tab + Tab
(with parameters that initialize all properties).
'Programming' 카테고리의 다른 글
오류 : EACCES : 권한이 거부되었습니다. '/ usr / local / lib / node_modules'액세스에 응답 (0) | 2020.06.12 |
---|---|
PostgreSQL에서 뷰의 CREATE VIEW 코드를 보는 방법은 무엇입니까? (0) | 2020.06.12 |
Java에서 참조로 문자열 전달? (0) | 2020.06.12 |
PHP를 통해 CSV로 내보내기 (0) | 2020.06.12 |
Android에서 GPS를 프로그래밍 방식으로 활성화 또는 비활성화하려면 어떻게해야합니까? (0) | 2020.06.12 |