Vb.net 使用propertyinfo对象获取属性的值

Vb.net 使用propertyinfo对象获取属性的值,vb.net,properties,propertyinfo,Vb.net,Properties,Propertyinfo,有没有办法通过propertyinfo对象获取对象属性的值 psudo代码: propertyinfoObject = Text myobject.toCommand(propertyinfoObject) 上面的psudo代码应执行与相同的操作 myobject.Text 我的目标是创建一个simpel Properties表单,该表单可用于任何对象(稍后我将使用关键字筛选出我希望使用的选项) 我的真实代码 Public Class PropertiesForm Dim propertyI

有没有办法通过propertyinfo对象获取对象属性的值

psudo代码:

propertyinfoObject = Text
myobject.toCommand(propertyinfoObject)
上面的psudo代码应执行与相同的操作

myobject.Text
我的目标是创建一个simpel Properties表单,该表单可用于任何对象(稍后我将使用关键字筛选出我希望使用的选项)

我的真实代码

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
已经为您完成了所有这些。过滤属性不是很明显,下面是如何:

该控件包含一个
BrowsableAttributes
属性,该属性允许您指定仅显示具有指定属性值的属性。可以使用现有属性,也可以使用自定义属性。这专门用于标记可见道具:

<AttributeUsage(AttributeTargets.Property)>
Public Class PropertyGridBrowsableAttribute
    Inherits Attribute

    Public Property Browsable As Boolean

    Public Sub New(b As Boolean)
        Browsable = b
    End Sub
End Class


BrowsableAttributes
是一个集合,因此您可以添加多个。

不是免费的,但PropertyGrid是否已经完成了所有这些功能?:)您说得太对了!我不知道它的存在。net框架非常大,当您是新手时,很容易错过som关键的东西:)。也许我应该从头到尾地读我的VB书,而不仅仅是在里面跳来跳去!
Public Class Employee
    <PropertyGridBrowsable(True)>
    Public Property FirstName As String
    ...
    <PropertyGridBrowsable(False)>
    Public Property PayRate As Decimal
    <PropertyGridBrowsable(False)>
    Public Property NationalInsuranceNumber As String
Dim emp As New Employee With {.Dept = EmpDept.Manager,
                                    .FirstName = "Ziggy",
                                    .PayRate = 568.98D,
                                     ...
                                    .NationalInsuranceNumber = "1234567"
                                   }

propGrid.BrowsableAttributes = New AttributeCollection(New PropertyGridBrowsableAttribute(True))

propGrid.SelectedObject = emp