Sunday, March 25, 2007

My First DSL: Object Model Designer

To learn and test out the DSL tools that come with the Visual Studio 2005 SDK, I've created a simple DSL to quickly create object models. The goal for this DSL was to have a 'class designer' that focused on object structure and not distract you with details.

You can create a new project using the Object Model Designer project template (its in C# Projects). The following image shows the project template for the Object Model Designer.



Each time you change your model, you have to regenerate the code (that represents that model) using the right-most button on the Solution Explorer or by selecting "Run Custom Tool" from the context menu of the MyModel.Designer.tt. This will generate the MyModel.Designer.cs file containing code for all classes in the model. The MyModel.cs is a demo implementation of how you would extend your model in code. All classes are generated as partial so you can regenerate your model anytime and might get compile errors for custom code that no longer 'connects' to the model code.

A MyModel.Designer.tt file is needed for every model (instance) you create in the project because the model is referenced in the .tt file. The actual .tt script is included from ObjectModelDesigner.tt.

You can download the installer for the Object Model Designer
here.

0 comments: