2022-02-02 15:56:37 +00:00
|
|
|
import std/macros
|
|
|
|
|
2022-02-02 16:05:59 +00:00
|
|
|
macro fieldValues*(obj: object): auto =
|
2022-02-02 15:56:37 +00:00
|
|
|
result = newNimNode(nnkTupleConstr)
|
|
|
|
let typ = getTypeImpl(obj)
|
|
|
|
let fields = typ[2]
|
|
|
|
for field in fields:
|
|
|
|
let name = field[0]
|
|
|
|
result.add newDotExpr(obj, name)
|
|
|
|
|
|
|
|
template fieldTypes*(T: type): type tuple =
|
|
|
|
typeof fieldValues(T.default)
|