예제 #1
0
        public void Add(TKey key, TValue value)
        {
            LookupValueCollection <TValue> values = null;

            if (!dictionary.TryGetValue(key, out values))
            {
                values = new LookupValueCollection <TValue>();
                dictionary.Add(key, values);
            }
            values.Add(value);
        }
예제 #2
0
 public LookupValueCollection <TValue> this[TKey key]
 {
     get
     {
         LookupValueCollection <TValue> values = null;
         if (dictionary.TryGetValue(key, out values))
         {
             return(values);
         }
         return(null);
     }
 }
예제 #3
0
        /// <summary>
        /// Finds node that represents the same instance as given value.
        /// </summary>
        /// <param name="value">Valid value representing an instance.</param>
        /// <returns></returns>
        private ObjectGraphNode getExistingNodeForValue(Value value)
        {
            int objectHashCode = value.InvokeDefaultGetHashCode();
            // are there any nodes with the same hash code?
            LookupValueCollection <ObjectGraphNode> nodesWithSameHashCode = objectNodesForHashCode[objectHashCode];

            if (nodesWithSameHashCode == null)
            {
                return(null);
            }
            else
            {
                // if there is a node with same hash code, check if it has also the same address
                // (hash codes are not uniqe - http://stackoverflow.com/questions/750947/-net-unique-object-identifier)
                ulong           objectAddress       = value.GetObjectAddress();
                ObjectGraphNode nodeWithSameAddress = nodesWithSameHashCode.Find(
                    node => { return(node.PermanentReference.GetObjectAddress() == objectAddress); });
                return(nodeWithSameAddress);
            }
        }