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

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 value As String)
            _name
= value
       
End Set
   
End Property

End Class

posted on 2008-11-07 09:34  笑看风云淡  阅读(2194)  评论(0编辑  收藏  举报

导航