Share via


DomainModel.CreateElement Method

Creates an element 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 CreateElement ( _
    partition As Partition, _
    elementType As Type, _
    propertyAssignments As PropertyAssignment() _
) As ModelElement
public virtual ModelElement CreateElement(
    Partition partition,
    Type elementType,
    PropertyAssignment[] propertyAssignments
)
public:
virtual ModelElement^ CreateElement(
    Partition^ partition, 
    Type^ elementType, 
    array<PropertyAssignment^>^ propertyAssignments
)
abstract CreateElement : 
        partition:Partition * 
        elementType:Type * 
        propertyAssignments:PropertyAssignment[] -> ModelElement 
override CreateElement : 
        partition:Partition * 
        elementType:Type * 
        propertyAssignments:PropertyAssignment[] -> ModelElement 
public function CreateElement(
    partition : Partition, 
    elementType : Type, 
    propertyAssignments : PropertyAssignment[]
) : ModelElement

Parameters

  • elementType
    Type: System.Type
    A non-abstract ___domain class defined in the DSL Definition.

Return Value

Type: Microsoft.VisualStudio.Modeling.ModelElement
The ModelElement that was created.

Remarks

This method is suitable for generated code. In ordinary programming, use the constructor of the ___domain class.

This example assumes the DSL Definition of the Minimal Language DSL solution template.

Examples

MyDslDomainModel dm = ...;
PropertyAssignment nameProperty = 
    new PropertyAssignment(ExampleElement.NameDomainPropertyId, "element1");
ExampleElement element = dm.CreateElement(
    dm.Store.DefaultPartition, 
    typeof(ExampleElement), 
    new PropertyAssignment[] {nameProperty}
   ) as ExampleElement;

The following example has the same effect:

ExampleElement element1 = new ExampleElement(dm.Store);
element1.Name = "element1";

.NET Framework Security

See Also

Reference

DomainModel Class

Microsoft.VisualStudio.Modeling Namespace

Other Resources

[redirect] Domain Model in the Generated API