Michel, Have you consider to retrieve a copy of the inner object using GetValue, alter it, and then overwriting the inner object with the modified copy using SetValue?
HTH, Stefan >-----Original Message----- >From: [EMAIL PROTECTED] >[mailto:[EMAIL PROTECTED] On Behalf >Of Michel Liesmons >Sent: Monday, July 21, 2003 11:28 PM >To: [EMAIL PROTECTED] >Cc: Michel Liesmons >Subject: Recursive Reflection for value types question > > >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"); >