Understanding Generated Properties and Methods

When you run text templates, you transform the domain classes and domain relationships in your domain model into classes. You can test these generated classes in the Visual Studio experimental build to help identify problems before your users create their own generated classes.

Each element in the domain model has a class. These classes have common language runtime (CLR) attributes, which provide metadata about the domain model to the store. Based on these attributes, you can manipulate the store using its reflective interface.

Generated classes are defined in DomainClasses.cs, DomainRelationships.cs, and DomainModel.cs. These files list all the classes that you have defined in your domain model and that will be available for use in the experimental build.

For example, you can define a Library domain class, a Person domain class, and a relationship between them (LibraryHasMembers). Each of these objects is represented as a generated class in the experimental build.

Properties and Methods in Custom Classes

Your language users can work with generated classes by using generated properties and methods. For example, if you have an instance of the LibraryHasMembers relationship, you can access the instance of the Library class at one end of the relationship (its source role, in this case) or the instance of the Person class at the other end (its target role).

When the Library class is generated, it has a generated property that is called Members and that contains many instances of the Person class. You can use this generated property to access all the instances of the Person class that are connected to the Library classes through a LibraryHasMembers relationship. You can also add members by using the standard Add method of collections. By using these generated properties, you can access the instance or instances of the classes that are connected to an instance at either end of a link.

You can also use generated methods, such as GetLink, on the class for the LibraryHasMembers relationship. This method returns the link when information, such as the elements on both ends of the link, is passed in to the method.

Preventing Generated Properties from Being Created

You can indicate that properties should not be generated for one or both role player classes. For example, you might take this step when you create a relationship to an existing type of domain class that you cannot change, such as a domain class that is already compiled in a DLL that you cannot change.

In addition to the generated types, you can define additional types that are part of the domain model. Typically, these additional types are rules that you have created.

See Also

Concepts

Functionality of the Generated API

Other Resources

Domain-Specific Language Tools Glossary