Enumerations

Adding enumerations to the model allows you to use them as property types in entities. Although they’re modeled in the same way entities are, you won’t be creating an association to an enumeration … rather, they’ll be available when creating properties in the select list of Type.

To add an enumeration, drag it from the toolbox and drop it on the design surface, renaming as you see fit.

The default value type for an enumeration is Int32, although you can change it to any valid .NET enum value type. Note, though, that if the enum is the type for an identifier property in any class (and, before you say anything, I have seen this), you won’t be able to change it to a type that’s not valid for identifiers. You’ll be given the option, but an error will be thrown and the change will be prevented (there was a point where we considered conditionally disallowing invalid types in the value type select list, but it turned out to be more confusing than this way).

Adding a value

Adding values is done in the same way as adding properties to an entity.

Code for the enum’s values will be generated in the order they appear in the designer. Since order matters unless you add value initializers, the designer allows you to reorder the values by dragging a highlighted value up and down the list.

You can get more control over the generated value by providing an initializer. Not all values need to be initialized, although you will get a warning if you set some but not others.

Removing a value

To remove a value, simply select it and hit the Delete key. It will be removed from the model completely without confirmation.

If enum values are being automatically generated due to the Flags attribute being set on the enum, these will be regenerated so that gaps don’t exist.

Flags

If your enum’s values are flags, the designer has some extra support to make value setting easier.

When adding a new value and the Values are Flags property is true, the designer will initialize the new value’s Value property to the next highest binary number available in the existing list of values. The same will happen if you clear the Value property, since flags have to have numeric values.

And if you don’t have a headache from the overuse of the word value, you are a stronger person than I.

Enumeration properties

Both the enum and the values have property window entries. Properties of the enum itself are:

PropertyDescription
Code Generation
Name String. The name of this enum.
Namespace String. The namespace for this enum.
Value Type String. The backing type for this enum in the code. Valid values are Byte, SByte, Int16, UInt16, Int32, UInt32, Int64 and UInt64
Values are Flags Boolean. If true, the [Flags] attribute will be output in the generated code and the values of the enum will be added in binary increments. If values already have initializers, they won't be changed.
Display
Fill Color Color. The color for enum's banner on the design surface.
Visible Boolean. If true, the enum will be visible on the design surface. If false, will be hidden. Can also be toggled via the context menu when the enum is selected.
Documentation
Comment Detail String. XML comment <Remarks> section
Comment Summary String. XML comment <Summary> section

Context Menu for Values

Right-clicking on an enum displays a Visual Studio context menu with some new choices pertinent to that enum.


Menu choiceDescription
Add new ValueAdds a value to the enum.
Collapse Available when the entity is fully expanded, this action hides the properties so that only the title is visible.
Expand Available when the entity is fully collapsed, this action shows the properties, revsersing the _Collapse_ action.
Cut, Copy, Paste, Delete You can cut or copy, then paste, properties. Pasting can be to the same entity or to other entities. The pasted elements will be adjusted so that they don't violate any rules (such as two elements not having the same name), but otherwise the properties will stay the same. If no properties are selected in the designer, the cut and copy options will be disabled. If no properties are in the clipboard, the paste option will be disabled.
Validate Checks the currently selected entity against the validation rules built into the designer. Errors or warnings are displayed in Visual Studio's Error List window. If no element is selected, this validates the design surface itself.
Validate All Checks all model elements against the afore mentioned validation rules. Errors or warnings are displayed in Visual Studio's Error List window.
Hide Element Hides the currently selected elements on the diagram. Any lines to or from that entity will be hidden as well. This does not remove the entity from the model, only makes it invisible in the diagram. Useful for tidying up a diagram that would otherwise be unreadable due to, for example, a common base class that all other classes inherit from. If no entity is selected, this option will be disabled.
Show Hidden Elements Unhides any elements that were previously hidden, along with their association or inheritance lines. If no elements are hidden, this option will be disabled.
Add values via Code Displays a dialog that lets you add multiple values using the designer's custom property syntax. See "Adding values via code" for more details.
Select One of the features of the Visual Studio property editor is the ability to edit properties of multiple items if they share that property. This submenu gives you the ability to select model elements by type so that you can conveniently edit properties of those elements together (e.g., setting the color of multiple classes all at once). If the pertinent element type isn't present in the designer, that option will be disabled.
Select all classes... Select all class elements in the designer
Select all enums... Select all enum elements in the designer
Select all associations... Select all association lines (both unidirectional and bidirectional) in the designer
Select all unidirectional associations... Select all unidirectiional association lines in the designer
Select all bidirectional associations... Select all bidirectional association lines in the designer
Properties Switches focus to the Properties window.

Enumeration Value properties

Properies of the enum values are:

PropertyDescription
Code Generation
NameString. The name of this value.
ValueInteger. The (optional) decimal value of this enum value.
Documentation
Comment DetailString. XML comment <Remarks> section
Comment SummaryString. XML comment <Summary> section

Context Menu for Values

Right-clicking on a value displays a Visual Studio context menu with some new choices pertinent to that value.


Menu choiceDescription
Add new ValueAdds a value to the enum.
EditActivates in-diagram editing for the value name
Cut, Copy, PasteYou can cut or copy, then paste, properties. Pasting can be to the same entity or to other entities. The pasted elements will be adjusted so that they don't violate any rules (such as two elements not having the same name), but otherwise the properties will stay the same. If no properties are selected in the designer, the cut and copy options will be disabled. If no properties are in the clipboard, the paste option will be disabled.
DeleteThe selected property will be removed from the entity.
ValidateChecks the currently selected entity against the validation rules built into the designer. Errors or warnings are displayed in Visual Studio's Error List window. If no element is selected, this validates the design surface itself.
Validate AllChecks all model elements against the afore mentioned validation rules. Errors or warnings are displayed in Visual Studio's Error List window.
Show Hidden ElementsUnhides any elements that were previously hidden, along with their association or inheritance lines. If no elements are hidden, this option will be disabled.
SelectOne of the features of the Visual Studio property editor is the ability to edit properties of multiple items if they share that property. This submenu gives you the ability to select model elements by type so that you can conveniently edit properties of those elements together (e.g., setting the color of multiple classes all at once). If the pertinent element type isn't present in the designer, that option will be disabled.
Select all classes...Select all class elements in the designer
Select all enums...Select all enum elements in the designer
Select all associations...Select all association lines (both unidirectional and bidirectional) in the designer
Select all unidirectional associations...Select all unidirectiional association lines in the designer
Select all bidirectional associations...Select all bidirectional association lines in the designer
PropertiesSwitches focus to the Properties window.

Adding Values via Code (custom property syntax)

You can quickly add a group of values as text, a great time saver for those cases where you have existing enums that you want to make persistent and add to the model.

The designer exposes a custom property syntax that allows you to specify values. The syntax is simply:

<Name> <= Value>

with an optional comma (,) at the end of each line, exactly as it would be in C#. This lets you cut and paste C# enumeration bodies into the value editor and have the model consume them directly.

To edit the values as text, select the enum and right-click to get its context menu. Choose Add values via Code and you’ll see a small window pop up with the current values:

Add, edit or remove text as required - when you click OK, all the properties will be replaced by the parsed values of the text in that window. Any unrecognized values will be discarded.

Next Step

Associations

Next Step

Adding Model Comments