Example #1
0
        // {{Aroush-2.9 Port issue, need to mimic java's IdentityHashMap

        /*
         * From Java docs:
         * This class implements the Map interface with a hash table, using
         * reference-equality in place of object-equality when comparing keys
         * (and values). In other words, in an IdentityHashMap, two keys k1 and k2
         * are considered equal if and only if (k1==k2). (In normal Map
         * implementations (like HashMap) two keys k1 and k2 are considered
         * equal if and only if (k1==null ? k2==null : k1.equals(k2)).)
         */
        // Aroush-2.9}}

        /// <summary>Adds a custom AttributeImpl instance with one or more Attribute interfaces. </summary>
        public virtual void  AddAttributeImpl(AttributeImpl att)
        {
            System.Type clazz = att.GetType();
            if (attributeImpls.Contains(clazz))
            {
                return;
            }
            System.Collections.ArrayList foundInterfaces;
            lock (knownImplClasses)
            {
                foundInterfaces = (System.Collections.ArrayList)knownImplClasses[clazz];
                if (foundInterfaces == null)
                {
                    // we have a strong reference to the class instance holding all interfaces in the list (parameter "att"),
                    // so all WeakReferences are never evicted by GC
                    knownImplClasses.Add(clazz, foundInterfaces = new System.Collections.ArrayList());
                    // find all interfaces that this attribute instance implements
                    // and that extend the Attribute interface
                    System.Type actClazz = clazz;
                    do
                    {
                        System.Type[] interfaces = actClazz.GetInterfaces();
                        for (int i = 0; i < interfaces.Length; i++)
                        {
                            System.Type curInterface = interfaces[i];
                            if (curInterface != typeof(Attribute) && typeof(Attribute).IsAssignableFrom(curInterface))
                            {
                                foundInterfaces.Add(new WeakReference(curInterface));
                            }
                        }
                        actClazz = actClazz.BaseType;
                    }while (actClazz != null);
                }
            }

            // add all interfaces of this AttributeImpl to the maps
            for (System.Collections.IEnumerator it = foundInterfaces.GetEnumerator(); it.MoveNext();)
            {
                WeakReference curInterfaceRef = (WeakReference)it.Current;
                System.Type   curInterface    = (System.Type)curInterfaceRef.Target;
                System.Diagnostics.Debug.Assert(curInterface != null, "We have a strong reference on the class holding the interfaces, so they should never get evicted");
                // Attribute is a superclass of this interface
                if (!attributes.ContainsKey(curInterface))
                {
                    // invalidate state to force recomputation in captureState()
                    this.currentState = null;
                    attributes.Add(new SupportClass.AttributeImplItem(curInterface, att));
                    if (!attributeImpls.ContainsKey(clazz))
                    {
                        attributeImpls.Add(new SupportClass.AttributeImplItem(clazz, att));
                    }
                }
            }
        }
Example #2
0
 private static System.Type GetClassForInterface(System.Type attClass)
 {
     lock (attClassImplMap)
     {
         WeakReference refz  = (WeakReference)attClassImplMap[attClass];
         System.Type   clazz = (refz == null) ? null : ((System.Type)refz.Target);
         if (clazz == null)
         {
             try
             {
                 string name = attClass.FullName + "Impl," + attClass.Assembly.FullName;
                 attClassImplMap.Add(attClass, new WeakReference(clazz = System.Type.GetType(name, true)));                                  //OK
             }
             catch (System.Exception e)
             {
                 throw new System.ArgumentException("Could not find implementing class for " + attClass.FullName);
             }
         }
         return(clazz);
     }
 }
Example #3
0
        void Add()
        {
            try
            {
                long count = 0;
                while (EndOfTest == false)
                {
                    wht.Add(count.ToString(), count.ToString());
                    Thread.Sleep(1);

                    string toReplace = (count - 10).ToString();
                    if (wht.Contains(toReplace))
                    {
                        wht[toReplace] = "aa";
                    }

                    count++;
                }
            }
            catch (Exception ex)
            {
                AnyException = ex;
            }
        }