Imports System.Reflection
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'Debug.Print(getvalue("xy"))
'Debug.Print(getvalue("xyz"))
'Debug.Print(getvalue("x"))
Dim mt As MethodInfo = GetType(Form1).GetMethod("add")
MsgBox(mt.Invoke(Me, {11, 22}))
End Sub
Function add(aa, bb)
Return aa + bb
End Function
Public x = 100
Public y = 200
Public z = 300
Public Function getvalue(s As String)
Dim ret = ""
For Each i In s.ToArray
ret = ret + i & "," & GetType(Form1).GetField(i).GetValue(Me) & vbCrLf
Next
Return ret
End Function
End Class
VB.net 通过反射取得变量值和通过反射调用函数
猜你喜欢
转载自blog.csdn.net/aa326358942/article/details/104325744
今日推荐
周排行