我在 Windows Phone 7 应用程序中的对象上设置字段时遇到问题(我怀疑它与紧凑框架有关,而不是特定于 Windows Phone 7)。我相信这是特定于设置struct
类型的值。通常我使用以下内容:
// 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);
不幸的是SetValueDirect
,Windows Phone 7 上不存在,并且简单地使用SetValue
不会对目标做任何事情。是否有另一种方法可以struct
通过反射在 WP7 上设置字段?