Hi,

I'm trying to write some code to read/write object members of structs.

I can not find a way to do this if the struct contains nested structs
because each time you GetValue() the embedded object, you get a copy-by-
value and you are modifying this copy, not the original structure.
I need to be able to do this on arrays of inner objects too.

In the code below, how do I read/write outer.inner.local ?
outer.GetType().GetField ("inner.local") does not seem to work.

Note that if you do not copy outer to an object yourself, and pass outer
directy, the copy will be done implicitly, and upon return outer is not
changed.

Thanks for any ideas.

Michel.


Code:

    struct inner_t
    {
      public string local;
    }

    struct outer_t
    {
      public string local;
      public inner_t inner;
    }

      outer_t outer = new outer_t();
      object outerObj = outer;
      outerObj.GetType().InvokeMember ("local", BindingFlags.SetField,
null, outerObj, new Object[] {"local1"});
      outerObj.GetType().GetField ("local").SetValue (outerObj, "local2");

Reply via email to