Exemple #1
0
        /// <summary>
        /// NetOffice method: dispose instance and all child instances
        /// </summary>
        /// <param name="disposeEventBinding">dispose event exported proxies with one or more event recipients</param>
        public virtual void Dispose(bool disposeEventBinding)
        {
            // skip check
            bool cancel = RaiseOnDispose();

            if (cancel)
            {
                return;
            }

            // in case object export events and
            // disposeEventBinding == true we dont remove the object from parents child list
            bool removeFromParent = true;

            // set disposed flag
            _isCurrentlyDisposing = true;

            // in case of object implements also event binding we dispose them
            IEventBinding eventBind = this as IEventBinding;

            if (disposeEventBinding)
            {
                if (!Object.ReferenceEquals(eventBind, null))
                {
                    eventBind.DisposeEventBridge();
                }
            }
            else
            {
                if (!Object.ReferenceEquals(eventBind, null) && (eventBind.EventBridgeInitialized))
                {
                    removeFromParent = false;
                }
            }

            // child proxy dispose
            DisposeChildInstances(disposeEventBinding);


            // remove himself from parent childlist
            if ((!Object.ReferenceEquals(_parentObject, null)) && (true == removeFromParent))
            {
                _parentObject.RemoveChildObject(this);
                _parentObject = null;
            }

            // call quit automaticly if wanted
            if (_callQuitInDispose)
            {
                CallQuit(Settings, Invoker, this);
            }

            // release proxy
            ReleaseCOMProxy();

            // clear supportList reference
            _listSupportedEntities = null;

            _isDisposed           = true;
            _isCurrentlyDisposing = false;
        }