我正在使用反射循环遍历当前实例的属性,并尝试确定属性是否为 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
关于.net - 检查属性是否为 bool 类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21706672/