/// <summary>
            /// Remove subtype.
            /// </summary>
            /// <param name="subtypeId">The subtype identifier.</param>
            public void RemoveSubType(NodeId subtypeId)
            {
                if (subtypeId != null && SubTypes != null)
                {
                    SubTypes.Remove(subtypeId);

                    if (SubTypes.Count == 0)
                    {
                        SubTypes = null;
                    }
                }
            }
Пример #2
0
        /// <summary cref="IDictionary.Remove" />
        public bool Remove(IReference key)
        {
            // validate key.
            if (!ValidateReference(key, false))
            {
                return(false);
            }

            m_version++;

            // look up the reference type.
            ReferenceTypeEntry entry = null;

            if (!m_references.TryGetValue(key.ReferenceTypeId, out entry))
            {
                return(false);
            }

            // handle reference to external targets.
            if (key.TargetId.IsAbsolute)
            {
                Dictionary <ExpandedNodeId, LinkedListNode <KeyValuePair <IReference, T> > > targets = null;

                if (key.IsInverse)
                {
                    targets = entry.InverseExternalTargets;
                }
                else
                {
                    targets = entry.ForwardExternalTargets;
                }

                if (targets == null)
                {
                    return(false);
                }

                LinkedListNode <KeyValuePair <IReference, T> > node;

                if (!targets.TryGetValue(key.TargetId, out node))
                {
                    return(false);
                }

                m_list.Remove(node);
                targets.Remove(key.TargetId);
            }

            // handle reference to internal target.
            else
            {
                NodeIdDictionary <LinkedListNode <KeyValuePair <IReference, T> > > targets = null;

                if (key.IsInverse)
                {
                    targets = entry.InverseTargets;
                }
                else
                {
                    targets = entry.ForwardTargets;
                }

                if (targets == null)
                {
                    return(false);
                }

                LinkedListNode <KeyValuePair <IReference, T> > node;

                if (!targets.TryGetValue((NodeId)key.TargetId, out node))
                {
                    return(false);
                }

                m_list.Remove(node);
                targets.Remove((NodeId)key.TargetId);
            }

            // remove empty reference.
            if (entry.IsEmpty)
            {
                m_references.Remove(key.ReferenceTypeId);
            }

            return(true);
        }