创建一个指定类型的元素。
命名空间: Microsoft.VisualStudio.Modeling
程序集: Microsoft.VisualStudio.Modeling.Sdk.11.0(在 Microsoft.VisualStudio.Modeling.Sdk.11.0.dll 中)
语法
声明
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
)
参数
- partition
类型:Microsoft.VisualStudio.Modeling.Partition
分区组件将创建的位置。
- elementType
类型:System.Type
在 DSL 定义的非抽象域类。
- propertyAssignments
类型:array<Microsoft.VisualStudio.Modeling.PropertyAssignment[]
为域类定义的字段的特性指定值。
返回值
类型:Microsoft.VisualStudio.Modeling.ModelElement
所创建的 ModelElement。
备注
此方法适用于生成的代码。在普通进行编程,请使用域类的构造函数。
此示例假定最小语言 DSL 解决方案模板的 DSL 定义。
示例
MyDslDomainModel dm = ...;
PropertyAssignment nameProperty =
new PropertyAssignment(ExampleElement.NameDomainPropertyId, "element1");
ExampleElement element = dm.CreateElement(
dm.Store.DefaultPartition,
typeof(ExampleElement),
new PropertyAssignment[] {nameProperty}
) as ExampleElement;
下面的示例具有相同的效果:
ExampleElement element1 = new ExampleElement(dm.Store);
element1.Name = "element1";
.NET Framework 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。
请参见
参考
Microsoft.VisualStudio.Modeling 命名空间