I am having trouble setting a field on an object in a Windows Phone 7 app (I suspect it's related to the compact framework, and not specific to Windows Phone 7). I believe this is specific to setting values that are of struct
types. Normally I use the following:
// fieldName is the name of the field I'm interested in setting
FieldInfo fieldInfo = target.GetType().GetField(fieldName);
// target is the object I'm setting the value on
// value is the value that I am setting
fieldInfo.SetValueDirect(__makeref(target), value);
Unfortunately SetValueDirect
doesn't exist on Windows Phone 7, and simply using SetValue
doesn't do anything to target. Is there an alternative way to set struct
fields on WP7 through reflection?