Freigeben über


DomainModel.CreateElementLink Method

Creates an element link of a specified type.

Namespace:  Microsoft.VisualStudio.Modeling
Assembly:  Microsoft.VisualStudio.Modeling.Sdk.10.0 (in Microsoft.VisualStudio.Modeling.Sdk.10.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

  • elementLinkType
    Type: System.Type
    A non-abstract domain relationship defined in the DSL Definition.

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

See Also

Reference

DomainModel Class

Microsoft.VisualStudio.Modeling Namespace

Other Resources

[redirect] Domain Model in the Generated API