Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check whether a property is of type Boolean or not

I am looping over the properties of the current instance using Reflection, and I'm trying to determine if a property is of type Boolean. I tried many things (typeof, GetType, etc.) but I'm not getting it working. Here's my code :

For Each prop As System.Reflection.PropertyInfo In Me.GetType.GetProperties()
     If prop.PropertyType Is Boolean Then 'Not Compiling
         ' Do Something if boolean
     End If
Next
like image 755
MaxiWheat Avatar asked Dec 09 '25 22:12

MaxiWheat


1 Answers

Try using the GetType operator (as opposed to the GetType method):

 If prop.PropertyType Is GetType(Boolean) Then
     ' Do Something if boolean
 End If
like image 51
p.s.w.g Avatar answered Dec 11 '25 12:12

p.s.w.g