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

Reply via email to