You can use fieldPairs to get field value by name.
type
Foo = object
field: int
proc `[]`(x: Foo, s: string, T: type): T =
for n, v in x.fieldPairs:
if n == s:
result = v
break
var foo = Foo(field: 123)
echo foo.field
echo foo["field", int]
Run
- Module typeinfo, can't access field by name. Bug or not? moigagoo
- Re: Module typeinfo, can't access field by name. Bug or not? slangmgh
- Re: Module typeinfo, can't access field by name. Bug or ... moigagoo
- Re: Module typeinfo, can't access field by name. Bug... slangmgh
