PropertyInfo.SetValue
Imports System
Imports System.Reflection
Imports Microsoft.VisualBasic
Public Class TestClass
Private myCaption As String = "A Default caption"
Public Property Caption() As String
Get
Return myCaption
End Get
Set
If myCaption <> value Then myCaption = value
End Set
End Property
End Class
Public Class TestPropertyInfo
Public Shared Sub Main()
Dim t As New TestClass()
Dim myType As Type = t.GetType()
Dim pinfo As PropertyInfo = myType.GetProperty("Caption")
Console.WriteLine(pinfo.GetValue(t, Nothing))
pinfo.SetValue(t, "changed.", Nothing)
Console.WriteLine(pinfo.GetValue(t, Nothing))
End Sub
End Class
Related examples in the same category