【发布时间】:2012-08-26 22:20:01
【问题描述】:
我一直在阅读其他示例,并且似乎可以通过传入字段的名称来分配字段的值。
private string fieldName; //contains the name of the field I want to edit
void IObserver.Update(object data)
{
FieldInfo field = this.GetType().GetField(fieldName);
if(field != null)
{
field.SetValue(this, data);
}
}
字段总是以 null 结尾,我不知道为什么
【问题讨论】:
标签: c# .net reflection field