FieldInfo.GetValue返回null

时间:2016-08-30 11:03:27

标签: c# reflection

我有这段代码:

FieldInfo fi = this.GetType().GetField(StringConstants.UNDERSCORE + phase, 
                                       BindingFlags.Instance | BindingFlags.NonPublic);

    if (fi != null)
    {
        itemPhase = fi.GetValue(this) as IItemPhase;
    }

    if (itemPhase != null) 
    {
        _currentPhase = phase;
        _itemVo.Phase = phase;
        itemPhase.PreparePhase();
    }

FieldInfo fi获取正确的值,因此找到了该字段。

enter image description here

但是FieldInfo.GetValue总是返回null:

enter image description here

...和类型匹配:

enter image description here

任何人都知道为什么?

1 个答案:

答案 0 :(得分:1)

根据评论,似乎引用this._buildPhase实际上指向 NULL ,这就是你得到这种行为的原因。