Domain-Specific Language Tools uses a unique path syntax to locate specific elements in a model using the following format: ExampleElementReferencesTargets.Targets/!Target
ExampleElementReferencesTargets
This format follows the tree of the model, for example the "ExampleElementReferencesTargets" above is a domain relationship and the ".Targets" is the Property Name of one of its roles. The "/!Target" designates that the path finishes on elements accessed by the role Target (Property Name of Sources in the illustration).
The Name property of a role is the name used in programming, to navigate from a domain relationship instance to one of the domain classes that it connects. The PropertyName property of a role is used to navigate from an element to the element or elements that are linked to it by the relationship.
The path syntax is very simple, although it's rather verbose. To demonstrate this, you can you can look at the Shape Map in the Component Models solution template. Start by creating a new domain-specific language, using the Component Models template in the wizard, the one mapping InPortShape to InPort. (For more information, see How to: Create Domain-Specific Language Solutions) Then open DSLDefinition.dsl file in Solution Explorer, and in the DSL Explorer window, look under Diagram node'sShape Maps node and select the first Shape Map called CommentBoxShape. There are some details in the normal Properties window, and more details in the DSL Details window.
Note |
|---|
| If the DSL Details window is not visible, click the DSL Details button on the DSL Designer toolbar. |
The Parent Element Path shows in the General tab of DSL Details window, when you have that Shape Map selected in the DSL Explorer.
The syntax of a path is separated by slashes.
Each segment is either a hop from an element to a link, or from a link to an element. Quite often, they come in pairs: hop from element to link, and then onto the element at the other end. (Actually, links - that is, instances of relationships - can also be the source or target of a relationship themselves; but in most cases, a path goes link/element/link/element...)
Each segment starts with a relationship name. If it's an element-to-link hop, it is "Relationship . Property"; if it's a link-to-element hop, it's "Relationship ! Role".
In the InPort shape map example, the parent element path begins
ComponentHasPorts.Component
From the main dsldefinition.dsl diagram, we can see that InPort is a subclass of ComponentPort, and has a relationship ComponentHasPorts, and the property is called Component.
When writing C# against this model, you can jump across a link in one go, using the property that the relationship generates on each of the classes it relates:
InPort port; ... Component c = port.Component;
but in Path Syntax, you have to do both hops explicitly. This makes it easier to get at the intermediate link if you need to. So we complete the hop from the link to the Component:
ComponentHasPorts.Component / ! Component
(You can omit the relationship name where it's the same as the previous segment.)
Notice that the name you use for the element-to-link hop is the PropertyName defined on the role - that's the name you see on the main diagram next to the corresponding line from the element's DomainClass. If you click on that role line, you'll see it in the properties window under PropertyName.
The name you use for the link-to-element hop is the role name defined on the Relationship for the destination end. So in the main diagram, if you click on the line on the other side of the Relationship, you'll see it listed as that role's Name in the properties window.
In some contexts, such as element merge directives, only the element-to-link part of the path is required.
See Also