我正在查看关于反射的https://stackoverflow.com/a/4132070/1529149 ..
特别是这个
Public Sub setProperty(ByVal obj As Object, ByVal propName As String, ByVal newValue As Object)
Dim prop As Reflection.PropertyInfo = obj.GetType().GetProperty(propName)
If Not prop Is Nothing AndAlso prop.CanWrite Then
prop.SetValue(obj, newValue, Nothing)
End If
End Sub
但我需要输入第一个变量作为字符串或动态的东西..
我看不到点设置
setProperty(FixedObject, "Dynamic Property", "Dynamic Results")
什么时候它会更强大
setProperty("Dynamic Object", "Dynamic Property", "Dynamic Results")
例如:
Dim billy As String = "Label"
Dim bob As Integer = 1
setProperty(billy+bob, "Text", "Results")
创建 Label1.Text = "results"
对获得类似的东西有任何帮助吗?(ps 我知道我可能必须在某处将 bob 转换为字符串,但我还是 VB 的新手)