要让 .NET 控制台应用程序在 Server 2003 上运行,我们必须将我们的核心库之一从 .NET 4.5 降级到 4.0。除此之外,这个库有一个执行一些反射的类,循环遍历对象的属性以使用 Propertyinfo.GetValue()
根据 the MSDN documentation , PropertyInfo.GetValue (Object)
仅在 .NET 4.5 中。在 .NET 4.0 中,this method存在,但形式为 PropertyInfo.GetValue (Object, Object[])
(额外的参数是为了知道如何处理索引属性)。
如果我们要降级此代码,我们需要知道当 PropertyInfo.GetValue Method (Object)
遇到索引属性时会发生什么,因此我们可以使用 PropertyInfo 镜像此功能。 GetValue 方法(对象,对象[])
。谁能帮忙?
最佳答案
文档对此并不清楚,但检查反编译器中的实现表明 property.GetValue(obj)
只需调用 property.GetValue(obj, null)
没有任何检查,也没有发现任何异常。您将从 property.GetValue(obj)
获得的任何异常因此正是您将从property.GetValue(obj, null)
得到的异常,您应该可以毫无问题地更新您的电话。
关于c# - System.Reflection.PropertyInfo.GetValue() - 降级 .NET 版本 - 缺少方法签名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21043363/