简体   繁体   中英

C# Visual Studio 2010: make custom preset classes

I usually make classes with the following layout:

    public class [classname]
    {
        #region Properties

        #endregion

        #region Initialization

        public [classname]()
        {

        }

        #endregion

        #region Events

        #endregion

        #region Methods

        #endregion
    }

Is there any way to make it so when I make a new class, this is automaticly made for me?

您可以使用JetBrains ReSharper创建和使用类模板。

In VS go to Tools -> Code Snippet Manager and select Visual c#. Navigate to show path it should be simular to this:

C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC#\Snippets\1033\Visual C#
or
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC#\Snippets\1033\Visual C#

Before changing something in there I recommend to close VS. Create a new File named 'TheRegions.snippet' and insert this:

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>TheRegions</Title>
            <Shortcut>TheRegions</Shortcut>
            <Description>Codesnippet</Description>
            <Author>Authorname</Author>
            <SnippetTypes>
                <SnippetType>Expansion</SnippetType>
            </SnippetTypes>
        </Header>
        <Snippet>
            <Declarations>
                <Literal Editable="false">
                    <ID>classname</ID>
                    <ToolTip>ClassName</ToolTip>
                    <Function>ClassName()</Function>
                    <Default>ClassNamePlaceholder</Default>
                </Literal>
            </Declarations>
            <Code Language="csharp"><![CDATA[

            #region Properties
            #endregion

            #region Initialization
            public $classname$ ()
            {
            }
            ~$classname$()
            {
            }
            #endregion

            #region Events
            #endregion

            #region Methods
            #endregion
            ]]>
            </Code>
        </Snippet>
    </CodeSnippet>
</CodeSnippets>

Copy that file the location, startup VS and type 'TheRegions' intellisense should come up.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM