代码之家  ›  专栏  ›  技术社区  ›  magol Nathaniel Roark

GetProperty在.NET 3.5中工作,但不在.NET 4中工作

  •  1
  • magol Nathaniel Roark  · 技术社区  · 14 年前

    我使用以下代码:

    protected object GetProperty(object target, string fieldName)
    {
        Type type = target.GetType();
        PropertyInfo mi = type.GetProperty(
            fieldName, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetProperty);
        object obj = mi.GetValue(target, null);
        return obj;
    }
    

    它在.NET 3.5中工作。但如果我改为.NET 4,那么mi将变为空。为什么?

    1 回复  |  直到 12 年前
        1
  •  5
  •   Michael Stum    14 年前

    目标在.NET 4中是否仍具有所需的属性?有相当多的API更改。