PropertyInfo.SetValue : PropertyInfo « Reflection « VB.Net






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

1.PropertyInfo.Attributes Property gets the attributes for this property.
2.PropertyInfo.CanRead
3.PropertyInfo.CanWrite
4.PropertyInfo.GetAccessors
5.PropertyInfo.GetGetMethod returns the public or non-public get accessor for this property.
6.Get and display the GetGetMethod Method for each property
7.Display the GetGetMethod without using the MethodInfo
8.PropertyInfo.GetIndexParameters
9.Get Index Parameters
10.PropertyInfo.GetSetMethod
11.Display the GetSetMethod without using the MethodInfo
12.PropertyInfo.MemberType
13.PropertyInfo.PropertyType Property
14.LocalVariableInfo Class (System.Reflection)_VB.htm