Validation Overview for Domain-Specific Languages
As the author of a domain-specific language, you can add constraints to your domain models to check for semantic correctness beyond what you can express in the syntax of that language. Users of your domain-specific languages can validate the models that they create from those languages and display the results.
You can specify constraints on a value property such as the following:
•If the value property is a string, it must not contain spaces.
•If the value property is a number, it must be smaller than another value property.
You can specify constraints on a relation such as the following:
•All the objects that are connected by a given relation must have different names.
•Following the relation must not lead back to the same object.
You define each constraint as a method within a partial class. The partial class is for the class of the domain model object that you want to validate. The constraint method uses the property, the relationship, and the role names that are defined in the domain model.
Nota
You can find the full domain class in the file DomainModel.cs.
The validation framework applies each constraint to each object in the model within the given domain class and its subclass. You can define a constraint on any domain class in the language, including the root model and its relations, and you can enable validation for any of the following events:
Menu
If you enable this option, users can validate a model by right-clicking anywhere in the model.
Save
If you enable this option, users validate a model every time they save it to a file so that they avoid inadvertently saving or processing an invalid model. A warning appears, but they can save the file anyway.
Open
If you enable this option, users validate a model every time they open it from a file. If you use Open, you don't need to use Load.
Load
If you enable this option, users validate a model every time they load it. Loading happens before a file is opened. If you use Load, you don't need to use Open.
Custom
If you enable this option, you invoke validation from your custom code. You can group validation methods into categories and then specify which category to invoke.
Each of these categories has a global switch in the Designer.dsldd file, and you can enable each validation method separately for any combination of the categories. In addition, you can define custom categories so that users can invoke particular sets of constraints. This technique is useful if you define custom commands.
See Also
Concepts
How to: Add Validation to a Domain Model
Adding Validation to Domain-Specific Language Solutions