DomainModel.CreateElementLink 方法
建立指定型別的項目連結。
命名空間: Microsoft.VisualStudio.Modeling
組件: Microsoft.VisualStudio.Modeling.Sdk.12.0 (在 Microsoft.VisualStudio.Modeling.Sdk.12.0.dll 中)
語法
'宣告
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
)
參數
- partition
類型:Microsoft.VisualStudio.Modeling.Partition
要在其中建立項目連結的資料分割。通常是 DefaultPartition。
- elementLinkType
類型:System.Type
在 DSL 定義中所定義的非抽象網域關聯性。
- roleAssignments
類型:array<Microsoft.VisualStudio.Modeling.RoleAssignment[]
新項目連結的關聯性角色指派陣列。
- propertyAssignments
類型:array<Microsoft.VisualStudio.Modeling.PropertyAssignment[]
如果網域關聯性定義其執行個體的屬性,您可以在此處指定它們的值。
傳回值
類型:Microsoft.VisualStudio.Modeling.ElementLink
建立的 ElementLink。
備註
建立連結此方法套用至產生的程式碼比對泛型程式設計。
下列範例會從最小的語言方案範本產生的 DSL 所定義的型別。
範例
使用這個方法,建立連結:
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;
更直接使用網域關聯性,此範例會建立相同連結:
ExampleElementReferencesTargets link = new
ExampleElementReferencesTargets(element1, element2);
如果網域關聯性定義角色在關聯類別的屬性,因此,,如果您不要連結的參考,可以建立連結使用角色屬性。 在最小的語言 DSL, ExampleElementReferencesTargets 關聯性定義角色屬性 Source 和 Target:
// Creates the link without returning a reference to it:
element1.Targets.Add(element2);
.NET Framework 安全性
- 完全信任立即呼叫者。這個成員無法供部分信任的程式碼使用。如需詳細資訊,請參閱從部分受信任程式碼使用程式庫。
請參閱
參考
Microsoft.VisualStudio.Modeling 命名空間