User Variables

User variables are used to add variable data into easy code generator templates, that are not related to already existing data such as system variables, column information etc. They can be used anywhere inside a template.

You can add user variables under <Code Snippet Generator> -> <User Variables>

User Variable Selection

Choose the variable you want to use and then either double click on it or press the left button to add it to your code. With <Add with capital> you can tell easy code generator to use the variable entered with a capital letter.

With the right button, you can open the input window to manage your user variables.

Manage User Variables

Here you can add, edit or delete user variables.

  • ID: primary key of the user variable, set by the system.
  • Name: the name of the variables.
  • Description: a short description for the user, to understand what this variable is for.
  • Default Value: here you can enter a default value or a part of the variable that always should be the same.

Example

We have a template with the following content:

using System;
using System.Data.SqlClient;
using System.Windows.Forms;

namespace {{<<systemvar>><<name=namespace>><<endsystemvar>>}}.classes
{
public partial class {{<<uservar>><<uservarID=4>><<cap=true>><<enduservar>>}}
{

}
}

As namespace we don’t use a static text but instead we use the system variable <namespace>. Right behind the code “public partial class ” we add a user variable with the name “calssName” (see image <User Variable Selection>). The number in front of the variable name indicates the primary key. This ID you will find back in the code snippet
{{<<uservar>><<uservarID=4>><<cap=true>><<enduservar>>}}. With <<cap=true>> we indicate that we want the variables value to be capitalized.

If we run this template, then easy code generator recognizes that we are using a user variable and pops up an input window and asks the user to enter the value:

It displays the variable name and the short description for the user. In the text box it displays the default value (if defined). Enter the value and press on the save button to continue parsing. If you click on <Save value as default>, the default value will be overwritten for future use.

The result will be:

using System;
using System.Data.SqlClient;
using System.Windows.Forms;

namespace EasyCodeGenerator.classes
{
    public partial class Products
    {
    }
}

As you can see, easy code generator replaced the system variable <namespace> with EasyCodeGenerator and the class name with Products.

User variables can be used anywhere inside a template. They also can be used on multiple places. When used more often, easy code generator checks this and only asks for the variable once during parsing. Even if you refer to other templates from within this template (see includes) and the same user variable is used in the referred template too, easy code generator will only ask you once to enter it’s value.

Note: try to use as few user variables as possible and try to derive names from already existing objects like table names etc. Like this your code will become even more consistent and therefore better.