.net - 检查属性是否为 bool 类型

标签 .net vb.net reflection types

我正在使用反射循环遍历当前实例的属性,并尝试确定属性是否为 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/

相关文章:

c# - 适用于 .NET 的商业兼容许可 SNMP 代理

vb.net - 如何使用多个分隔符分割字符串

python - Python 中的优雅反射?

C# 使用通过反射找到的类型作为泛型

c# - 如何根据项目中的类制作枚举变量

.net - 温莎城堡问题

c# - 是否可以在两个项目中声明一个部分类

java - 奇怪的 JVM 与 .NET CLR 性能差异(短命对象 + 虚拟调用)

.net - 在 VB.NET 中获取 .NET Framework 版本

vb.net - 如何在 VB .net 中以编程方式修复字符串中的括号?