.net – 检查属性是否为Boolean类型

前端之家收集整理的这篇文章主要介绍了.net – 检查属性是否为Boolean类型前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用Reflection循环遍历当前实例的属性,并且我正在尝试确定属性是否为Boolean类型.我尝试了很多东西(typeof,GetType等),但我没有让它工作.这是我的代码

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

解决方法

尝试使用 GetType operator(而不是 GetType method):

If prop.PropertyType Is GetType(Boolean) Then
     ' Do Something if boolean
 End If

猜你在找的VB相关文章