如何确认.net中的属性是否属于Boolean类型?
- 内容介绍
- 文章标签
- 相关推荐
本文共计173个文字,预计阅读时间需要1分钟。
我正在使用Reflection遍历当前实例的属性,并尝试确定属性是否为Boolean类型。尝试了许多方法(如typeof、GetType等),但都没有让它工作。这是我的代码:
csharpFor Each prop As System.Reflection.PropertyInfo
我正在使用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
本文共计173个文字,预计阅读时间需要1分钟。
我正在使用Reflection遍历当前实例的属性,并尝试确定属性是否为Boolean类型。尝试了许多方法(如typeof、GetType等),但都没有让它工作。这是我的代码:
csharpFor Each prop As System.Reflection.PropertyInfo
我正在使用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

