I am extracting several properties of the control. This is how I used to retrieve properties (with pinfo of type PropertyInfo):
value = pinfo.GetValue(obj, nothing)
This worked fine, but now I come across a property that has an optional value, and I get an error message telling me that the number of parameters is incorrect. So I changed my code to this:
Dim index As Object() = {Nothing}
value = pinfo.GetValue(obj, index)
At this point, I did not receive an error message, but this code does not get a good value. It only works if I replace Nothing with the default value provided by the property accessory ...
But I don’t know what the default is! And this code is inside a function that retrieves properties that do not have additional values, so I cannot change the code, especially for one case.
Any idea? I am working on .NET 2.0
EDIT: additional comments on the case leading to the problem
Here is an example of the property leading to the problem:
ReadOnly Property Foo(Optional ByVal Number As Integer = -1) As String
Get
If Number = -1 Then
Return "Your number is the default number: " & Number
Else
Return "Your number is " & Number
End If
End Get
End Property
With this property, none of the above codes returns a good string.
It would be best to try the first code for general purposes, catch the corresponding exception, and then dynamically get the default value of the parameter (in this case, a number) and enter it so that I can call getValuewith this default value.
, ?