【发布时间】:2016-12-19 18:41:15
【问题描述】:
有没有办法通过 propertyinfo 对象获取对象属性的值?
伪代码:
propertyinfoObject = Text
myobject.toCommand(propertyinfoObject)
上面的伪代码应该和上面的一样
myobject.Text
我的目标是创建一个适用于任何对象的简单属性表单(稍后我将使用关键字过滤出我希望使用的选项)。
我的真实密码
Public Class PropertiesForm
Dim propertyInfoVar() As PropertyInfo
Dim Properties As New Form2
Dim listItem As New ListViewItem
Dim stringarray() As String
Public Sub New(ByRef sender As Object)
propertyInfoVar = sender.GetType().GetProperties()
For Each p In propertyInfoVar
stringarray = {p.Name.ToString, #INSERT VALUE SOMEHOW HERE#}
listItem = New ListViewItem(stringarray)
Properties.ListView1.Items.Add(listItem)
Next
Properties.Visible = True
End Sub
编辑 只需按照下面的建议使用 propertyGrid!
【问题讨论】:
-
不是没有,但 PropertyGrid 不是已经做了所有这些了吗?
-
:) 你说的太对了!我不知道它存在。 .net 框架是如此之大,以至于当你是新手时很容易错过一些关键的东西:)。也许我应该从头到尾阅读我的 VB 书,而不仅仅是在里面跳来跳去!
标签: vb.net properties propertyinfo