I found C# code for it here
So I tried
Public Function checkProperty(ByVal objectt As Object, ByVal propertyy As String) As Boolean
Dim type As Type = objectt.GetType
Return type.GetMethod(propertyy)
End Function
But it throws an error at type.GetMethod(propertyy)
saying "Value of type 'System.Reflection.MethodInfo' cannot be converted to 'Boolean'."
What to do?
First, C# code checks for presence of a method, not a property. Second, C# code compares return to null
:
Public Function checkProperty(ByVal objectt As Object, ByVal propertyy As String) As Boolean
Dim type As Type = objectt.GetType
Return type.GetProperty(propertyy) IsNot Nothing
End Function
EDIT To check for fields, change the method as follows:
Public Function checkField(ByVal objectt As Object, ByVal fieldName As String) As Boolean
Dim type As Type = objectt.GetType
Return type.GetField(fieldName) IsNot Nothing
End Function
it is returning the MethodInfo instead and you can just change it as follow:
Public Function checkProperty(ByVal objectt As Object, ByVal propertyy As String) As Boolean
Dim type As Type = objectt.GetType
Return type.GetMethod(propertyy) IsNot Nothing
End Function
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With