Class

PropertyInfo


Description

Used to get information about properties via the Introspection system.

Methods

Name

Parameters

Returns

Shared

GetAttributes

AttributeInfo()

Value

obj As Object

Variant

base As Object, Assigns value As Variant

Property descriptions


PropertyInfo.CanRead

CanRead As Boolean

If True, the property is a simple value property or has a Get accessor.

This property is read-only.

This example checks the CanRead property before taking an action.

Var d As DateTime = DateTime.Now
Var myProperties() As Introspection.PropertyInfo = Introspection.GetType(d).GetProperties
For Each prop As Introspection.PropertyInfo In myProperties
  If prop.CanRead Then
    ' take action here
  End If
Next

PropertyInfo.CanWrite

CanWrite As Boolean

If True, the property is a simple value property or has a Set accessor.

This property is read-only.

This example checks the CanRead property before taking an action.

Var d As DateTime = DateTime.Now
Var myProperties() As Introspection.PropertyInfo = Introspection.GetType(d).GetProperties
For Each prop As Introspection.PropertyInfo In myProperties
  If prop.CanWrite Then
    ' take action here
  End If
Next

PropertyInfo.IsComputed

IsComputed As Boolean

If True, it is a computed property.

This property is read-only.


PropertyInfo.IsPrivate

IsPrivate As Boolean

If True, the item has Private scope.

This property is read-only.

The following example checks the IsPrivate property before taking an action.

Var d As DateTime = DateTime.Now
For Each prop As Introspection.PropertyInfo In Introspection.GetType(d).GetProperties
  If prop.IsPrivate Then
    ' take an action here..
  End If
Next

PropertyInfo.IsProtected

IsProtected As Boolean

Is True, the item has Protected scope.

This property is read-only.

Var d As DateTime = DateTime.Now
For Each prop As Introspection.PropertyInfo In Introspection.GetType(d).GetProperties
  If prop.IsProtected Then
    ' take an action here..
  End If
Next

PropertyInfo.IsPublic

IsPublic As Boolean

If True, the item has Public scope.

This property is read-only.

This example checks the IsPublic property before taking an action.

Var d As DateTime = DateTime.Now
For Each prop As Introspection.PropertyInfo In Introspection.GetType(d).GetProperties
  If prop.IsPublic Then
    ' take an action here..
  End If
Next

PropertyInfo.IsShared

IsShared As Boolean

If True, it is a shared property and does not require a Self parameter when called by Introspection.

This property is read-only.

This example reports whether the properties for the DateTime class are shared.

Var d As DateTime = DateTime.Now
Var myProperties() As Introspection.PropertyInfo = Introspection.GetType(d).GetProperties
For Each prop As Introspection.PropertyInfo In myProperties
  If prop.CanRead Then
    ListBox1.AddRow(prop.IsShared.ToString)
  End If
Next

PropertyInfo.Name

Name As String

The name of the item. This is only the class name. To get the full namespace path, use FullName instead.

This property is read-only.

This code gets the list of properties for the passed type instance.

Var d As DateTime = DateTime.Now
For Each prop As Introspection.PropertyInfo In Introspection.GetType(d).GetProperties
  ListBox1.AddRow(prop.Name)
Next

PropertyInfo.PropertyType

PropertyType As TypeInfo

Contains the property's datatype.

This property is read-only.

This example gets the data type of each property of the DateTime class.

Var d As DateTime = DateTime.Now
Var myProperties() As Introspection.PropertyInfo = Introspection.GetType(d).GetProperties
For Each prop As Introspection.PropertyInfo In myProperties
  ListBox1.AddRow(prop.PropertyType.FullName)
Next

Method descriptions


PropertyInfo.GetAttributes

GetAttributes As AttributeInfo()

Returns an array of AttributeInfo objects.

The following gets the attributes of window1.

Var myAttributes() As Introspection.AttributeInfo = Introspection.GetType(Window1).GetAttributes

PropertyInfo.Value

Value(obj As Object) As Variant

Returns the value of the property, given an instance of the property's class.


PropertyInfo.Value

Value(base As Object, Assigns value As Variant)

Sets the value of the property, given an instance of the property's class. If the property is shared, specify Nil for the base parameter.

This example gets and then changes the value of the Compact property:

Var json As New JSONItem
Var myProperties() As Introspection.PropertyInfo = Introspection.GetType(json).GetProperties

For Each p As Introspection.PropertyInfo In myProperties
  Select Case p.Name
  Case "Compact"
    Var value As Boolean = p.Value(json)

    MessageBox("Current Compact value = " + value.ToString)

    ' Toggle Compact
    p.Value(json) = Not value

    MessageBox("New Compact value = " + json.Compact.ToString)
  End Select
Next

To get an array property, you assign the value back to an array. This example uses a class (TestClass that has TestArray() As String with two values. It gets the array values:

Var t As New TestClass

Var ti As Introspection.TypeInfo
ti = Introspection.GetType(t)

Var p() As Introspection.PropertyInfo
p = ti.GetProperties

For Each pi As Introspection.PropertyInfo In p
  Var pt As Introspection.TypeInfo
  pt = pi.PropertyType

  Select Case pi.Name
  Case "TestArray"
    If pt.IsArray Then
      If pi.Value(t).ArrayElementType = 8 Then ' String
        Var s() As String

        s = pi.Value(t)

        MessageBox("Array = (" + String.FromArray(s, ",") + ")")
      End If
    End If
  End Select
Next

Sample code

This example gets the list of properties for the passed type instance.

Var d As DateTime = DateTime.Now
Var myProperties() As Introspection.PropertyInfo = Introspection.GetType(d).GetProperties
For Each prop As Introspection.PropertyInfo In myProperties
  ListBox1.AddRow(prop.Name)
Next

Compatibility

All project types on all supported operating systems.