     res
 
   toJson: ->
+    # update args in case they were changed
+    for arg in @args()
+      @_data.args[arg.name()] = arg._jsonDef()
     @_data
+
   @fromJson: (json) ->
     new ReflectResult(json)
 

    @_name
  label: ->
    @_def.label || @name()
  type: ->
    @_type
  isStruct: ->

      res[field.name()] = field.visit(callback)
    res

  addOpenField: (name, type) ->
    console.error 'operation not support for non-open structs' unless @isOpen()
    new_field = if type == 'struct'
      new StructMemberField(@, name, {type: {kind: 'struct', open: true}})
    else
      new ValueMemberField(@, name, type, {type: type})

    @fields().push(new_field)

    new_field

  _jsonDef: ->
    res = super
    if @isOpen()
      # update members if the struct is open
      res.type.members = {}
      for f in @fields()
        res.type.members[f.name()] = f._jsonDef()
    res

class ReflectResult
  constructor: (@_data) ->
    @_args = []
