代码生成器工具,用于生成属性和支持字段

Mat*_*lay 3 c#

我在VS2008和C#的工作,我正在寻找一个(免费)代码生成工具来生成getter和setter的属性,以及为后盾的私人领域去.在VS模板啄不作现场去用它.只是寻找一些更好的东西.

我曾经看过一个网站,您可以在其中构建此代码,然后将其从网页上保存并粘贴到您的代码中.

And*_*are 6

您可以创建自定义代码段来执行您想要的任何操作.这是我在VS2005中用于创建具有支持字段的属性的一个:

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>prop</Title>
                    <!-- the shortcut below will show in your intellisense 
                         window - set it to whatever you wish -->
            <Shortcut>_prop</Shortcut>
            <Description>Code snippet for a property</Description>
            <Author>Andrew</Author>
            <SnippetTypes>
                <SnippetType>Expansion</SnippetType>
            </SnippetTypes>
        </Header>
        <Snippet>
            <Declarations>
                <Literal>
                    <ID>type</ID>
                    <Default>String</Default>
                    <ToolTip>property type</ToolTip>
                </Literal>
                <Literal>
                    <ID>pname</ID>
                    <Default>_name</Default>
                    <ToolTip>private field name</ToolTip>
                </Literal>
                <Literal>
                    <ID>name</ID>
                    <Default>Name</Default>
                    <ToolTip>property name</ToolTip>
                </Literal>
            </Declarations>
            <Code Language="csharp">
                    <![CDATA[$type$ $pname$;

            public $type$ $name$
            {
                get { return this.$pname$; }
                set { this.$pname$ = value; }
            }$end$]]>
            </Code>
        </Snippet>
    </CodeSnippet>
</CodeSnippets>
Run Code Online (Sandbox Code Playgroud)

将其保存whatever.snippet在此位置调用的文件中:

"C:\Documents and Settings\<YOU>\My Documents\Visual Studio 2005\Code Snippets\Visual C#\My Code Snippets"