示例#1
0
        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);
            }
        }