Code generator tool to create property and support fields

I work in VS2008 and C #, and I am looking for a (free) code generator to generate a property using getter and setter, as well as a backup private field to work with. The thingy pattern in VS does not make a box for this. Just looking for something a little better.

I once saw a website where you could create this code, and then paste it and copy from the web page into your code.

+3
source share
5 answers

You can create your own fragments to do anything. Here is one that I used in VS2005 to create properties using support fields:

<?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>

Save this in a file with a name whatever.snippetin this place:

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

+5
source

StackOverlfow, , , , . , , .

, :

Visual Studio?

0

CodeSmith . ,

<%-- 
Name: Database Table Properties
Authors: Paul Welter , Yordan Georgiev
Description: Create a list of properties from a database table with a region for each prop
--%>
<%@ CodeTemplate Language="C#" TargetLanguage="C#" Debug="False" Description="Create a list of properties from database table." %>
<%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Category="Context" Description="Table that the object is based on." %>
<%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %>
<%@ Assembly Name="SchemaExplorer" %>
<%@ Import Namespace="SchemaExplorer" %>

<% foreach (ColumnSchema column in this.SourceTable.Columns) {  %>

#region <%= StringUtil.ToPascalCase(column.Name) %>
private <%= CSharpAlias[column.SystemType.FullName] %> _<%= StringUtil.ToPascalCase(column.Name) %>;

public <%= CSharpAlias[column.SystemType.FullName] %> <%= StringUtil.ToPascalCase(column.Name) %>
{
    get { return _<%= StringUtil.ToPascalCase(column.Name) %>; }
    set { _<%= StringUtil.ToPascalCase(column.Name) %> = value; }
}
#endregion <%= StringUtil.ToPascalCase(column.Name) %>
<% } %>
0

, , # VS 2008 . .NET 2.0, .

, :

public int Number { get; set; }

private int _number;
public int Number
{
get { return this._number; }
set { this._number = value; }
}
0

Source: https://habr.com/ru/post/1703965/


All Articles