【问题标题】:Check whether a property is of type Boolean or not检查属性是否为布尔类型
【发布时间】:2014-03-09 12:33:55
【问题描述】:

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

【问题讨论】:

  • 试试If prop.PropertyType Is GetType(Boolean) Then

标签: .net vb.net reflection types


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2014-03-25
    • 1970-01-01
    • 1970-01-01
    • 2013-04-02
    • 1970-01-01
    • 2022-01-26
    • 1970-01-01
    • 2015-02-19
    • 2014-03-06
    相关资源
    最近更新 更多