Beispiel #1
0
        /// <summary>
        /// Clones this instance using the specified ancestor.
        /// </summary>
        /// <param name="ancestor">The ancestor.</param>
        public virtual IFeatureInstance Clone(IClassType ancestor)
        {
            IPrecursorInstance NewPrecursor = new PrecursorInstance(ancestor, this);

            Debug.Assert(NewPrecursor.Ancestor == ancestor);

            IFeatureInstance ClonedObject = new FeatureInstance(Owner, Feature);

            foreach (IPrecursorInstance PrecursorInstance in PrecursorList)
            {
                ClonedObject.PrecursorList.Add(PrecursorInstance);
            }
            ClonedObject.PrecursorList.Add(NewPrecursor);
            ClonedObject.SetIsForgotten(IsForgotten);
            ClonedObject.SetIsKept(IsKept);
            ClonedObject.SetIsDiscontinued(IsDiscontinued);
            ClonedObject.SetInheritBySideAttribute(InheritBySideAttribute);

            if (OriginalPrecursor.IsAssigned)
            {
                ClonedObject.OriginalPrecursor.Item = OriginalPrecursor.Item;
            }

            return(ClonedObject);
        }
        private void MergeInheritedFeatures(IClass item, ISealableDictionary <IFeatureName, InheritedInstanceInfo> byNameTable, out ISealableDictionary <IFeatureName, IFeatureInstance> mergedFeatureTable)
        {
            mergedFeatureTable = new SealableDictionary <IFeatureName, IFeatureInstance>();

            foreach (KeyValuePair <IFeatureName, InheritedInstanceInfo> ImportedEntry in byNameTable)
            {
                IFeatureName          ImportedKey      = ImportedEntry.Key;
                InheritedInstanceInfo ImportedInstance = ImportedEntry.Value;

                IFeatureInstance NewInstance = MergeCreateNewInstance(item, ImportedKey, ImportedInstance, out InstanceNameInfo SelectedInstanceInfo);

                StableReference <IPrecursorInstance> OriginalPrecursor = new StableReference <IPrecursorInstance>();
                IList <IPrecursorInstance>           PrecursorList     = new List <IPrecursorInstance>();
                foreach (InstanceNameInfo Item in ImportedInstance.PrecursorInstanceList)
                {
                    if (Item == SelectedInstanceInfo)
                    {
                        foreach (IPrecursorInstance PrecursorInstance in Item.Instance.PrecursorList)
                        {
                            PrecursorList.Add(PrecursorInstance);
                        }
                    }
                    else
                    {
                        IPrecursorInstance NewPrecursor = new PrecursorInstance(Item.Ancestor, Item.Instance);
                        PrecursorList.Add(NewPrecursor);
                    }

                    if (Item.Instance.OriginalPrecursor.IsAssigned)
                    {
                        OriginalPrecursor.Item = Item.Instance.OriginalPrecursor.Item;
                    }
                }

                if (OriginalPrecursor.IsAssigned)
                {
                    NewInstance.OriginalPrecursor.Item = OriginalPrecursor.Item;
                }
                else if (PrecursorList.Count > 0)
                {
                    NewInstance.OriginalPrecursor.Item = PrecursorList[0];
                }

                Debug.Assert(NewInstance.PrecursorList.Count == 0);
                foreach (IPrecursorInstance PrecursorInstance in PrecursorList)
                {
                    NewInstance.PrecursorList.Add(PrecursorInstance);
                }

                mergedFeatureTable.Add(ImportedKey, NewInstance);
            }
        }