DomainModel::CreateElementLink Method (Partition^, Type^, array<RoleAssignment^>^, array<PropertyAssignment^>^)
Creates an element link of a specified type.
Assembly: Microsoft.VisualStudio.Modeling.Sdk.12.0 (in Microsoft.VisualStudio.Modeling.Sdk.12.0.dll)
public: virtual ElementLink^ CreateElementLink( Partition^ partition, Type^ elementLinkType, array<RoleAssignment^>^ roleAssignments, array<PropertyAssignment^>^ propertyAssignments )
Parameters
- partition
-
Type:
Microsoft.VisualStudio.Modeling::Partition^
The partition where the element link is to be created. Typically the DefaultPartition.
- elementLinkType
-
Type:
System::Type^
A non-abstract domain relationship defined in the DSL Definition.
- roleAssignments
-
Type:
array<Microsoft.VisualStudio.Modeling::RoleAssignment^>^
An array of relationship role assignments for the new element link.
- propertyAssignments
-
Type:
array<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 =
dm.CreateElementLink(dm.Store.DefaultPartition,
typeof(ExampleElementReferencesTargets),
new RoleAssignment[] { sourceRole, targetRole},
null)
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: element1.Targets.Add(element2);