DomainModel.CreateElementLink Method
Creates an element link of a specified type.
Namespace: Microsoft.VisualStudio.Modeling
Assembly: Microsoft.VisualStudio.Modeling.Sdk.11.0 (in Microsoft.VisualStudio.Modeling.Sdk.11.0.dll)
Syntax
'Declaration
Public Overridable Function CreateElementLink ( _
partition As Partition, _
elementLinkType As Type, _
roleAssignments As RoleAssignment(), _
propertyAssignments As PropertyAssignment() _
) As ElementLink
public virtual ElementLink CreateElementLink(
Partition partition,
Type elementLinkType,
RoleAssignment[] roleAssignments,
PropertyAssignment[] propertyAssignments
)
public:
virtual ElementLink^ CreateElementLink(
Partition^ partition,
Type^ elementLinkType,
array<RoleAssignment^>^ roleAssignments,
array<PropertyAssignment^>^ propertyAssignments
)
abstract CreateElementLink :
partition:Partition *
elementLinkType:Type *
roleAssignments:RoleAssignment[] *
propertyAssignments:PropertyAssignment[] -> ElementLink
override CreateElementLink :
partition:Partition *
elementLinkType:Type *
roleAssignments:RoleAssignment[] *
propertyAssignments:PropertyAssignment[] -> ElementLink
public function CreateElementLink(
partition : Partition,
elementLinkType : Type,
roleAssignments : RoleAssignment[],
propertyAssignments : PropertyAssignment[]
) : ElementLink
Parameters
partition
Type: Microsoft.VisualStudio.Modeling.PartitionThe partition where the element link is to be created. Typically the DefaultPartition.
elementLinkType
Type: TypeA 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.
Return Value
Type: Microsoft.VisualStudio.Modeling.ElementLink
The ElementLink created.
Remarks
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.
Examples
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);
.NET Framework Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.
See Also
Reference
Microsoft.VisualStudio.Modeling Namespace