Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
How to: Set Element Merge Directive Details

How to: Set Element Merge Directive Details 

You use the DSL Details window together with the Domain-Specific Language Designer and DSL Explorer. The Element Merge Directive Details channel appears when you add or click an element merge directive in DSL Explorer as described in the following procedure.

To set element merge directive details for an element

  1. In DSL Explorer, right-click the element, and click Add New Element Merge Directive.

    The DSL Details window appears with the Element Merge Directive Details channel open.

  2. In the Indexing class list, click the class on which to index the merge.

    The tool window caption for this information also appears. For example, the caption might read “DSL Details – Merge Directive: ExampleModel accepts ExampleElement." From the caption, you can identify that ExampleModel is the class for which you are defining a merge directive and ExampleElement is the class that will be merged into the ExampleModel.

  3. Click one of these options:

    • Forward merge to a different domain class. After you click this option, type the domain path of the new domain class in the box. This domain class will manage the merge as long as the domain class is in scope. For example, a domain path might be "ClassAReferenceClassB.ClassB", where ClassAReferenceClassB is a domain relationship and ClassB is the property name of the role upon which the indexing class interacts.

    • Process merge by creating links at paths. After you click this option, type a domain path in the box. This path instructs the Domain-Specific Language Designer on how to merge the incoming indexing class. For example, you can specify the location in which to create a link and the link, which connects the instance of the parent with the instance of the indexing class. To do this, you must define a merge directive for ClassA. ClassA participates in a domain relationship, which is named ClassAContainsClassB, and contains a collection of ClassB classes, if you specify the indexing class as ClassB. You can specify the link path as ClassAContainsClassB.Bs, where property Bs is the property name of the role that ClassA plays.

  4. (Optional) Select the Uses custom accept check box to specify custom code.

    If you select this check box, you can decide whether an instance of the indexing class should be accepted for merging into the parent class. For example, you have the ClassAContainsClassB domain relationship and you are defining a merge directive for ClassA with ClassB as the incoming indexing class. If you specify the custom accept to be true, and you transform all templates, a method call to CanMergeClassB appears in the method ClassA::CanMerge method. You will need to create this custom method ClassA::CanMergeClassB.

  5. (Optional) Select the Uses custom merge check box to specify that you want to create custom code for the merge.

    If you select this check box, you must merge the classes yourself. Paths are ignored. You can use the example in the previous step. If you select the Uses custom merge check box, you must implement ClassA::MergeRelateClassB and ClassA::MergeDisconnectClassB. For example, when ClassB is added to the ClassA’s collection, you will want to assign a unique value in the ClassB.Identification domain property. You can implement the expected methods as follows:

    public class ClassA
    {
          private void MergeRelateClassB(DslModeling::ModelElement sourceElement, DslModeling::ElementGroup elementGroup)
          {
                ClassB classB = sourceElement as ClassB;
                if ( classB != null)
                {
                      // add to the ClassA’s collection. 
                      this.Bs.Add( classB);
    
                      // Here you can assign the Identification to ClassB
                      classB.Identification = DateTime.Now.ToString();
                      
                }
          }
          private void MergeDisconnectClassB(DslModeling::ModelElement sourceElement)
          {
                ClassB classB = sourceElement as ClassB;
                if ( classB != null)
                {
                      this.Bs.Add( classB);
                }
          }
    }
    
  6. (Optional) Select the Applies to subclasses check box, which allows any subclasses of ClassB to be merged automatically with ClassA.

See Also

Community Additions

ADD
Show:
© 2015 Microsoft