DomainModel.CreateElementLink Method (Partition, Type, RoleAssignment[], PropertyAssignment[])


Creates an element link of a specified type.

Namespace:   Microsoft.VisualStudio.Modeling
Assembly:  Microsoft.VisualStudio.Modeling.Sdk.12.0 (in Microsoft.VisualStudio.Modeling.Sdk.12.0.dll)

public virtual ElementLink CreateElementLink(
	Partition partition,
	Type elementLinkType,
	RoleAssignment[] roleAssignments,
	PropertyAssignment[] propertyAssignments


Type: Microsoft.VisualStudio.Modeling.Partition

The partition where the element link is to be created. Typically the DefaultPartition.

Type: System.Type

A non-abstract domain relationship defined in the DSL Definition.

Type: Microsoft.VisualStudio.Modeling.RoleAssignment[]

An array of relationship role assignments for the new element link.

Type: Microsoft.VisualStudio.Modeling.PropertyAssignment[]

If the domain relationship defines properties for its instances, you can assign their values here.

This method of creating a link is more suitable for generated code than for ordinary programming.

The following examples use the types defined in a DSL generated from the Minimal Language solution template.

To create a link using this method:

ExampleElement element1, element2;
MyLanguageDomainModel dm = ...;

RoleAssignment sourceRole = new RoleAssignment(ExampleElementReferencesTargets.SourceDomainRoleId, element1);
RoleAssignment targetRole = new RoleAssignment(ExampleElementReferencesTargets.TargetDomainRoleId, element2);
ExampleElementReferencesTargets link1 = 
        new RoleAssignment[] { sourceRole, targetRole},
        as ExampleElementReferencesTargets;

This example creates the same link more directly using the domain relationship:

ExampleElementReferencesTargets link = new 
    ExampleElementReferencesTargets(element1, element2);

If the domain relationship defines role properties on the classes that it associates, and if you do not want a reference to the link, then you can create the link using the role properties. In the Minimal Language DSL, the ExampleElementReferencesTargets relationship defines role properties Source and Target:

// Creates the link without returning a reference to it:

Return to top