public virtual void SetReferenceTargetElement <T>(IModelElementInstance referenceSourceElement, T referenceTargetElement) where T : IModelElementInstance { IModelInstance modelInstance = referenceSourceElement.ModelInstance; string referenceTargetIdentifier = ReferenceTargetAttribute.GetValue <String>(referenceTargetElement); IModelElementInstance existingElement = modelInstance.GetModelElementById(referenceTargetIdentifier); if (existingElement == null || existingElement.Id != referenceTargetElement.Id) { throw new ModelReferenceException("Cannot create reference to model element " + referenceTargetElement + ": element is not part of model. Please connect element to the model first."); } SetReferenceIdentifier(referenceSourceElement, referenceTargetIdentifier); }
public virtual void SetReferenceTargetElement <TTarget>(ModelElementInstanceImpl referenceSourceParentElement, TTarget referenceTargetElement) where TTarget : IModelElementInstance { ModelInstanceImpl modelInstance = (ModelInstanceImpl)referenceSourceParentElement.ModelInstance; string identifier = ReferenceTargetAttribute.GetValue <String>(referenceTargetElement); IModelElementInstance existingElement = modelInstance.GetModelElementById(identifier); if (existingElement == null || !existingElement.Equals(referenceTargetElement)) { throw new ModelReferenceException("Cannot create reference to model element " + referenceTargetElement + ": element is not part of model. Please connect element to the model first."); } TSource referenceSourceElement = modelInstance.NewInstance <TSource>(ReferenceSourceElementType); SetReferenceSource(referenceSourceParentElement, referenceSourceElement); SetReferenceIdentifier(referenceSourceElement, identifier); }
protected internal virtual void PerformAddOperation(ModelElementInstanceImpl referenceSourceParentElement, IModelElementInstance referenceTargetElement) { ModelInstanceImpl modelInstance = (ModelInstanceImpl)referenceSourceParentElement.ModelInstance; string referenceTargetIdentifier = ReferenceTargetAttribute.GetValue <String>(referenceTargetElement); IModelElementInstance existingElement = modelInstance.GetModelElementById(referenceTargetIdentifier); if (existingElement == null || !existingElement.Equals(referenceTargetElement)) { throw new ModelReferenceException("Cannot create reference to model element " + referenceTargetElement + ": element is not part of model. Please connect element to the model first."); } else { ICollection <TSource> referenceSourceElements = _referenceSourceCollection.Get <TSource>(referenceSourceParentElement); TSource referenceSourceElement = modelInstance.NewInstance <TSource>(_referenceSourceType); referenceSourceElements.Add(referenceSourceElement); SetReferenceIdentifier(referenceSourceElement, referenceTargetIdentifier); } }