Why aren't UnityEngine.UIElements.*Event type ids constants?

protected override void ExecuteDefaultActionAtTarget(EventBase evt)
        {
            switch (evt.eventTypeId)
            {
                case MouseEnterEvent.TypeId():
                    {
                        break;
                    }
            }
            // Note: This can't be turned into a switch statement; Attempting to declare a case
            // on *Event.TypeId() results in a compilation error. It complains that the 'type
            // TypeId doesn't exist'. I assume the problem is that you need to switch on a constant
            // or an expression that evaluates to a constant. Not sure why the error indicates a
            // missing type problem.
            if (evt.eventTypeId == MouseEnterEvent.TypeId())
            {
                OnMouseEnter((MouseEnterEvent)evt);
            }

I have two questions about the above code snippet.

  1. The switch block doesn’t compile (see the note). Can someone help me understand what the error is saying?
  2. The documentation encourages default action overrides rather than events for performance reasons. That makes sense. What was the reasoning behind the design choice to not make event type ids constants? Rather than being able to jump to handlers, a bunch of conditionals need to be evaluated at runtime?

Like your comment speculates, it’s because you’re trying to use a runtime expression in your case statement. There are a few kinds of expressions you can switch over (including types) and it looks like the compiler just spit out a warning related to one of them among the possibilities, as compilers are wont to do.

Ah okay, I guess I didn’t realize you could switch on a types. Makes sense.