I've been eschewing hard-coded programming for almost forty years now. The most egregious example I ever came across was in COBOL:
77 FOUR PIC S9(4) VALUE 5.

It took me ages to debug that.

I like your solution - very much. Especially the completely generic don't-care-about-type nature.

If I were to do it from scratch, I'd do it via an iterative hash table, which could also cope with typing. Do you see any problem with that?

Kia ora,
Laurie