private TiResponse destroy(TiRequestParams data)
        {
            if (!data.ContainsKey("handle"))
            {
                throw new ReflectionException("\"invokeMethod\" request missing \"handle\" param");
            }

            string handle   = (string)data["handle"];
            object instance = InstanceRegistry.getInstance(handle);

            if (instance == null)
            {
                throw new ReflectionException("\"invokeMethod\" request invalid handle \"" + handle + "\"");
            }

            // remove from parent view
            var propertyInfo = instance.GetType().GetProperty("Parent");

            if (propertyInfo != null)
            {
                var parent = propertyInfo.GetValue(instance);
                if (parent != null)
                {
                    propertyInfo = parent.GetType().GetProperty("Children");
                    if (propertyInfo != null)
                    {
                        var children = propertyInfo.GetValue(parent);
                        var remove   = children.GetType().GetMethod("Remove");
                        remove.Invoke(children, new object[] { instance });
                    }
                }
            }

            // call Dispose method
            var dispose = instance.GetType().GetMethod("Dispose");

            if (dispose != null)
            {
                dispose.Invoke(instance, null);
            }

            // call Finalize method
            var finalize = instance.GetType().GetMethod("Finalize");

            if (finalize != null)
            {
                finalize.Invoke(instance, null);
            }

            // remove global reference
            InstanceRegistry.removeInstance(handle);

            return(null);
        }
        private void eventHandler(Object sender, EventArgs e, String eventName, String handle, WebBrowser browser)
        {
            TiResponse response = new TiResponse();

            response["_hnd"] = handle;
            response["type"] = eventName;

            string senderHandle = "";
            bool   senderExists = InstanceRegistry.containsInstance(sender);

            if (senderExists)
            {
                senderHandle = InstanceRegistry.getInstanceHandleByValue(sender);
            }
            else
            {
                senderHandle = InstanceRegistry.createHandle(sender);
            }
            response["sender"] = senderHandle;

            string eventArgsHandle = "";
            bool   eventArgsExists = InstanceRegistry.containsInstance(e);

            if (eventArgsExists)
            {
                eventArgsHandle = InstanceRegistry.getInstanceHandleByValue(e);
            }
            else
            {
                eventArgsHandle = InstanceRegistry.createHandle(e);
            }
            response["eventArgs"] = eventArgsHandle;

            response["error"] = null;
            if (e.GetType() == typeof(ErrorEventArgs))
            {
                response["error"] = ((ErrorEventArgs)e).error;
            }

            browser.InvokeScript("execScript", new string[] { "tiwp8.fireEvent(" + JsonConvert.SerializeObject(response, Formatting.None) + ")" });

            if (!senderExists)
            {
                InstanceRegistry.removeInstance(senderHandle);
            }
            if (!eventArgsExists)
            {
                InstanceRegistry.removeInstance(eventArgsHandle);
            }
        }