Skip to content

Enumerations

Danny Quinn edited this page Sep 29, 2018 · 2 revisions

To add an enumeration two extra lines are required. The first defines the enum attributes and the second how each item in the enumeration will be created.

Keywords Enum and Template must always appear together or not at all.

The example below shows an enum definition with all options specified.

Detail Enum1

The resulting code file...

Detail Enum2

Enum

Enum accepts between one and four parameters. The order is not important but the name of the enum is required.

Detail Enum3

The flags parameter adds the [Flags] attribute to the enum to allow bitwise operators.

The base type can be specified as another parameter. The default value is int as the base type.

Valid types are byte, sbyte, short, Int16, ushort, int, Int32, uint, long, Int64 and ulong.

The remaining parameter is the access modifier. This is either public or internal. The default is public.

As mentioned, order is not important and the following is valid.

Detail Enum4

Template

Template determines how each item in the enumeration is created.

Each item in the template must be a valid name from the column list.

For a basic enumeration use...

Detail Enum5

Which creates...

Detail Enum6

to add initializer values...

Detail Enum7

or to add a description...

Detail Enum8

and for a description and initializer...

Detail Enum9

Finally, the product table defined below has no columns that are suitable for creating an enumeration.

ID cannot be used as it starts with a number, and ProductName contains spaces.

Detail Enum10

In this case create another column with a suitable enumeration name and put an asterisk immediately after the column name.

Detail Enum11

The asterisk lets the parser know that this column should be ignored when creating the sql file. Only ID and ProductName will be created in the sql file.

Details Sql1