C# 2.0 Compilation Units

By default, PowerDesigner generates one source file for each class, interface, delegate, or other type, and bases the source directory structure on the namespaces defined in the model.

You may want instead to group multiple classifiers in a single source file and/or construct a directory structure independent of your namespaces.

A compilation-unit allows you to group multiple types in a single source file. It consists of zero or more using-directives followed by zero or more global-attributes followed by zero or more namespace-member-declarations.

PowerDesigner models compilation units as artifacts with a stereotype of <<Source>> and allows you to construct a hierarchy of source directories using folders. Compilation units do not have diagram symbols, and are only visible inside the Artifacts folder in the Browser.

You can preview the code that will be generated for your compilation unit at any time, by opening its property sheet and clicking the Preview tab.

Creating a Compilation Unit

To create an empty compilation unit from the Browser, right-click the model or the Artifacts folder and select New > Source, enter a name (being sure to retain the .cs extension), and then click OK.

Note: You can create a compilation unit and populate it with a type from the Generated Files tab of the property sheet of the type by clicking the New tool in the Artifacts column.

Adding a Type to a Compilation Unit

You can add types to a compilation unit by:
  • Dragging and dropping the type diagram symbol or browser entry onto the compilation unit browser entry.
  • Opening the compilation unit property sheet to the Objects tab and using the Add Production Objects tool.
  • Opening the type property sheet to the Generated Files tab and using the Add/Remove tool in the Artifacts column. Types that are added to multiple compilation units will be generated as partial types and you can specify the compilation unit in which each of their attributes and methods will be generated.

Creating a Generation Folder Structure

You can control the directory structure in which your compilation units will be generated by using artifact folders:
  1. Right-click the model or a folder inside the Browser Artifacts folder, and select New > Artifact Folder.
  2. Specify a name for the folder, and then click OK to create it.
  3. Add compilation units to the folder by dragging and dropping their browser entries onto the folder browser entry, or by right-clicking the folder and selecting New > Source.
Note: Folders can only contain compilation units and other folders. To place a type in the generation folder hierarchy, you must first add it to a compilation unit.