nim-ethers/ethers/fields.nim

13 lines
309 B
Nim
Raw Permalink Normal View History

import std/macros
2022-02-02 16:05:59 +00:00
macro fieldValues*(obj: object): auto =
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)