Topic
Prev Next

C# Example

This sample program demonstrates how easy it is to navigate, query and report on the current model using any Microsoft .NET language. This example is written in C#.

When run, it will print the names of every Package in the model you are currently using.

Create the project

In the Project Browser, select the Package in which to create the template and then use the ribbon or context menu to display the Model Wizard; select the 'Application Patterns' tab.

On the 'Application Patterns' tab, select the Microsoft C# > RepositoryInterface template. (You can choose from either the 3.5 or the 4.0 framework versions.) Specify the destination folder on the file system where the project template will be created, and click on the OK button.

Open the project

A Package structure similar to this will be created for you.

Expand the structure until you locate the Repository Interface n.n diagram and open it.

Build the script

The commands on this diagram will operate on the active build configuration. Before executing them, double-click on the Analyzer Scripts link and select the checkbox next to the Repository Interface build configuration.

Run the script

Double-click on the Run link to open the Console. The Console will pause after completion so you can read the output from the program; this output will also be sent to the 'Script' tab of the System Output window.  You can alter this by changing the code.

Debug the script

Select the 'Program' Class from the Project Browser and press Ctrl+E to open the source code.

Place a breakpoint in one of the functions and then double-click on the DebugRun link. When the breakpoint is encountered, the line of code will become highlighted in the editor, as shown: