본문 바로가기
개발, IT

Visual Studio 에서 C# try catch 자동완성 (코드조각) 사용자정의

by Nabi™ 2020. 10. 7.

기본적으로 Visual Studio에서 제공하는 기능으로

try를 입력후 Tab, Tab 키를 누르면 자동으로 try catch 구문이 작성된다.

 

기본제공하는 형식에서 내가 자주쓰는 형식으로 변경하려면 다음과 같이 하면 된다.

 

1. 디렉토리 이동

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

 

2. try.snippet 파일 수정

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
	<CodeSnippet Format="1.0.0">
		<Header>
			<Title>try</Title>
			<Shortcut>try</Shortcut>
			<Description>Code snippet for try catch</Description>
			<Author>Microsoft Corporation</Author>
			<SnippetTypes>
				<SnippetType>Expansion</SnippetType>
				<SnippetType>SurroundsWith</SnippetType>
			</SnippetTypes>
		</Header>
		<Snippet>
			<Declarations>
				<Literal>
					<ID>expression</ID>
					<ToolTip>Exception type</ToolTip>
					<Function>SimpleTypeName(global::System.Exception)</Function>
				</Literal>
			</Declarations>
			<Code Language="csharp"><![CDATA[try 
	    {	        
		    $selected$
			$end$
	    }
	    catch ($expression$ ex)
		{
			log.Error(ex.StackTrace, ex);
			throw ex;		    
	    }]]>
			</Code>
		</Snippet>
	</CodeSnippet>
</CodeSnippets>

3. 끝~

 

 

댓글