Is it possible to get the fieldnames of a struct inside a macro?

No, for exactly the same reasons as in Unpack named tuples (does anyone know how to do it?) - #9 by rdeits

The macro is, in general, expanded before the struct exists and certainly before the symbol being passed into the macro has a value. This just isn’t something macros can do for you, at least not in a way you can rely on.

An @generated function is probably the solution here, although it’s hard to know without knowing what you’re actually trying to accomplish. Can you give any more context?

3 Likes