thanks for the replay, I have tried it and now works, here is code
    
    
    type
      Person = object
        name: string
        age: int
        city: string
    
    
    proc getFields(t: type):seq[string] =
        var p: Person
        for field, v in p.fieldPairs:
            when v.type is t:
                result.add(field)
    
    template withField(x: untyped, T: type, actions: untyped) =
        var x: T
        when x.astToStr in getFields(T):
            actions
        else:
            discard
    
    withField(name, string):
        name = "jk"
        echo name
    
    withField(fullname, string):  # fullname does not exist, actions will be 
discard
        fullname = "jk"
        echo fullname
    
    
    Run

Reply via email to