Simplified and more reliable implementation of EnumEntry and Enumerated.