Nice programing

Visual Studio의 메서드에 대한 코드 조각

nicepro 2021. 1. 9. 11:39
반응형

Visual Studio의 메서드에 대한 코드 조각


Visual Studio에서 예를 들어 입력 할 수 있습니다.

...에 대한 TAB TAB

코드 조각이 나타납니다.

비공개, 공개 등의 메소드에 대한 내장 코드 스 니펫도 있습니까?


ctor : 기본 생성자

소품 : 속성

propg : 읽기 전용 속성

sim : static int main방법

svm : static void main방법

여기에 좋은 목록이 있습니다 . 직접 만들고 싶다면 Snippet Designer 가 매우 좋습니다.

다음은 Visual Studio 2017 용 모든 Visual C # 코드 조각입니다.


메서드 조각을 Visual Studio Extension 으로 다운로드 할 수 있습니다 .

다음을 지원합니다.

method (typical method)

vmethod (virtual method)

smethod (static method)

xmethod (extension method)
  1. Visual Studio에서 도구확장 및 업데이트 메뉴로 이동합니다 .

  2. 확장 및 업데이트관찰

  3. 검색 필드 (오른쪽 위)에 "C # Methods Code Snippets"를 입력합니다.


다음은 Visual Studio 2010 용 사용자 지정 코드 조각을 만드는 데 사용한 단계이지만 Visual Studio 2008에서도 작동합니다.

method.snippet 이라는 새 텍스트 파일을 만들고 다음을 붙여 넣습니다.

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>method</Title>
            <Shortcut>method</Shortcut>
            <Description>Code snippet for method</Description>
            <Author>Kevin Hogg</Author>
            <SnippetTypes>
                <SnippetType>Expansion</SnippetType>
            </SnippetTypes>
        </Header>
        <Snippet>
            <Declarations>
                <Literal>
                    <ID>methodname</ID>
                    <ToolTip>Method name</ToolTip>
                    <Function>MethodName()</Function>
                    <Default>MethodNamePlaceholder</Default>
                </Literal>
            </Declarations>
            <Code Language="csharp"><![CDATA[public void $methodname$ ()
    {
        $end$
    }]]>
            </Code>
        </Snippet>
    </CodeSnippet>
</CodeSnippets>

Windows 탐색기의 snippets 폴더에 파일을 복사합니다.

  • Visual Studio 2010 : C : \ Program Files (x86) \ Microsoft Visual Studio 10.0 \ VC # \ Snippets \ 1033 \ Visual C #
  • Visual Studio 2008 : C : \ Program Files (x86) \ Microsoft Visual Studio 9.0 \ VC # \ Snippets \ 1033 \ Visual C #

파일을 저장하면 코드 조각이 자동으로로드되므로 이제 Visual Studio를 열고 다음을 입력 할 수 있습니다.

method<tab><tab>

* 여기서 <tab>은 Tab키보드 키입니다.

이제 이름을 변경할 수 있도록 MethodNamePlaceholder가 강조 표시된 다음이 생성 된 것을 볼 수 있습니다.

public void MethodNamePlaceholder()
{

}

사용 가능한 모든 목록을 보려면 다음을 수행하십시오 snippet.

  • 를 눌러 CTRL+KCTRL+X

MSDN에서도 언급 한 내가 사용하는 일부 스 니펫은 다음과 같습니다.

  1. ' #if #if 지시문과 #endif 지시문을 만듭니다.
  2. ' #region #region 지시문 및 #endregion 지시문을 만듭니다.
  3. ~ 포함하는 클래스에 대한 소멸자를 만듭니다.
  4. attribute Attribute에서 파생되는 클래스에 대한 선언을 만듭니다.
  5. 체크 된 블록을 생성합니다.
  6. class 클래스 선언을 만듭니다.
  7. ctor 포함하는 클래스에 대한 생성자를 만듭니다.
  8. cw Creates a call to WriteLine.
  9. do Creates a do while loop.
  10. else Creates an else block.
  11. enum Creates an enum declaration.
  12. equals Creates a method declaration that overrides the Equals method defined in the Object class.
  13. exception Creates a declaration for a class that derives from an exception (Exception by default).
  14. for Creates a for loop.
  15. foreach Creates a foreach loop.
  16. forr Creates a for loop that decrements the loop variable after each iteration.
  17. if Creates an if block.
  18. indexer Creates an indexer declaration.
  19. interface Creates an interface declaration.
  20. invoke Creates a block that safely invokes an event.
  21. iterator Creates an iterator.
  22. iterindex Creates a "named" iterator and indexer pair by using a nested class.
  23. lock Creates a lock block.
  24. mbox Creates a call to MessageBox.Show. You may have to add a reference to System.Windows.Forms.dll.
  25. namespace Creates a namespace declaration.
  26. prop Creates an auto-implemented property declaration.
  27. propfull Creates a property declaration with get and set accessors.
  28. propg Creates a read-only auto-implemented property with a private "set" accessor.
  29. sim Creates a static int Main method declaration.
  30. struct Creates a struct declaration.
  31. svm Creates a static void Main method declaration.
  32. switch Creates a switch block.
  33. try Creates a try-catch block.
  34. tryf Creates a try-finally block.
  35. unchecked Creates an unchecked block.
  36. unsafe Creates an unsafe block.
  37. using Creates a using directive.
  38. while Creates a while loop.

I made my own snippet for a method. The XML code for it is the following, and you can add it to a file called "my_method.snippet" (or whatever_you_want.snippet) in C:\Users\YOUR_USERNAME\Documents\Visual Studio 2012\Code Snippets\Visual C#\My Code Snippets (your path might be different because I use VS2012):

<CodeSnippet Format="1.0.0">
    <Header>
        <Title>method</Title>
        <Shortcut>method</Shortcut>
        <SnippetTypes>
            <SnippetType>Expansion</SnippetType>
        </SnippetTypes>
    </Header>
    <Snippet>
        <Declarations>
            <Literal>
                <ID>access_modifier</ID>
                <Default>private</Default>
            </Literal>
            <Literal>
                <ID>return_type</ID>
                <Default>void</Default>
            </Literal>
            <Literal>
                <ID>name</ID>
                <Default>New_method</Default>
            </Literal>
        </Declarations>
        <Code Language="csharp">
            <![CDATA[$access_modifier$ $return_type$ $name$ ()
    {
    $end$
    }]]>
        </Code>
    </Snippet>
</CodeSnippet>

You can create customs snippets. Like this:

http://www.mediafire.com/file/gz3tzjnydk5/meth.snippet


The code snippet for properties is:

propTABTAB

ReferenceURL : https://stackoverflow.com/questions/292164/code-snippets-for-methods-in-visual-studio

반응형