vb.net反射中如何将字符串转化为对象实例

来源:互联网 发布:java怎么固定gui位置 编辑:程序博客网 时间:2024/03/28 21:40
Imports System.Reflection

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim o As Object = Activator.CreateInstance(Type.GetType("A.a"))'工程名称.类名
        Dim MyProperty As PropertyInfo = o.GetType().GetProperty("NAME")
        Dim objValue As Object = "Bbb"
        MyProperty.SetValue(o, objValue, Nothing)
        Dim objReturn() As Object
        MsgBox(MyProperty.GetValue(o, objReturn).ToString())
    End Sub
End Class

Public Class a
    private  _name As String
    Public _id As Integer

    Public Property NAME() As String
        Get
            Return _name
        End Get

        Set(ByVal valueAs String)
            _name = value
        End Set
    End Property

End Class
原创粉丝点击