Example #1
0
        public void DestroyInstance(object instance)
        {
            _managedObjects.Remove(instance);
//			const type : Class = _reflector.getClass(instance);
//			Type type = _reflector.GetType(instance);
            Type            type            = instance.GetType();
            TypeDescription typeDescription = GetTypeDescription(type);

            for (PreDestroyInjectionPoint preDestroyHook = typeDescription.preDestroyMethods;
                 preDestroyHook != null; preDestroyHook = preDestroyHook.next as PreDestroyInjectionPoint)
            {
                preDestroyHook.ApplyInjection(instance, type, this);
            }
        }
        private void AddPreDestroyMethodPoints(TypeDescription description, MethodInfo[] methods)
        {
            List <OrderedInjectionPoint> orderedInjectionPoints = new List <OrderedInjectionPoint> ();

            foreach (MethodInfo method in methods)
            {
                object[] injections = method.GetCustomAttributes(PRE_DESTROY_ATTRIBUTE_TYPE, true);
                if (injections.Length == 0)
                {
                    continue;
                }

                PreDestroy attr = injections [0] as PreDestroy;

                PreDestroyInjectionPoint injectionPoint = new PreDestroyInjectionPoint(attr.order, method);
                orderedInjectionPoints.Add(injectionPoint);
            }

            orderedInjectionPoints.Sort(SortInjectionPoints);
            foreach (PreDestroyInjectionPoint point in orderedInjectionPoints)
            {
                description.AddPreDestroyMethod(point);
            }
        }