internal void Fire(string type)
 {
     var @event = new Event(type);
     @event.IsTrusted = true;
     Dispatch(@event);
 }
        internal bool Dispatch(Event @event, EventTarget targetOverride = null)
        {
            var target = targetOverride ?? this;

            @event.DispatchFlag = true;
            @event.Target = target;
            @event.EventPhase = EventPhase.CapturingPhase;

            var eventPath = new List<EventTarget>();
            var node = (this as Node)?.ParentNode;
            while (node != null)
            {
                eventPath.Add(node);
                node = node.ParentNode;
            }
            eventPath.Reverse();

            foreach (var item in eventPath)
            {
                if (@event.StopPropagationFlag)
                    break;

                item.Invoke(@event);
            }

            @event.EventPhase = EventPhase.AtTarget;
            if ([email protected])
                Invoke(@event);

            if (@event.Bubbles)
            {
                eventPath.Reverse();

                foreach (var item in eventPath)
                {
                    if (@event.StopPropagationFlag)
                        break;

                    item.Invoke(@event);
                }
            }

            @event.DispatchFlag = false;
            @event.EventPhase = EventPhase.None;
            @event.CurrentTarget = null;

            return [email protected];
        }
        internal void Invoke(Event @event)
        {
            @event.CurrentTarget = this;

            foreach (var record in EventListeners)
            {
                if (@event.StopImmediatePropagationFlag)
                    return;

                if (record.Type != @event.Type)
                    continue;

                if (@event.EventPhase == EventPhase.CapturingPhase &&
                    !record.Capture)
                    continue;

                if (@event.EventPhase == EventPhase.BubblingPhase &&
                    record.Capture)
                    continue;

                try
                {
                    record.Listener(@event);
                }
                catch (Exception)
                {

                }
            }
        }
        /// <summary>
        /// Dispatches a synthetic event event to target.
        /// </summary>
        /// <param name="event"></param>
        /// <returns>
        /// <c>true</c> if either <see cref="Event"/>'s <see cref="Event.Cancelable"/> attribute value
        /// is <c>false</c> or its <see cref="Event.PreventDefault"/> method was not invoked,
        /// and <c>false</c> otherwise.
        /// </returns>
        public bool DispatchEvent(Event @event)
        {
            if (@event.DispatchFlag || [email protected])
                throw new Exception();

            @event.IsTrusted = false;
            return Dispatch(@event);
        }