Reputation: 73
To get a .NET console application running on Server 2003, we're having to downgrade one of our core libraries from .NET 4.5 to 4.0. Among other things, this library has a class that performs some reflection, cycling through an object's properties to get their values using Propertyinfo.GetValue()
According to the MSDN documentation, PropertyInfo.GetValue (Object)
is in .NET 4.5 only. In .NET 4.0, this method exists, but in the form PropertyInfo.GetValue (Object, Object[])
(the extra parameter is to know how to handle indexed properties).
If we're to downgrade this code, we need to know what happens when PropertyInfo.GetValue Method (Object)
encounters an indexed property, so we can mirror this functionality using PropertyInfo.GetValue Method (Object, Object[])
. Can anyone help?
Upvotes: 7
Views: 3039
Reputation:
The documentation isn't clear about this, but inspecting the implementation in a decompiler shows that property.GetValue(obj)
just calls property.GetValue(obj, null)
without any checks whatsoever, and without catching any exceptions whatsoever. Any exception that you would get from property.GetValue(obj)
is therefore exactly the exception that you would get from property.GetValue(obj, null)
, and you should have no problems updating your calls.
Upvotes: 7