我有一个名为 ticket 的 VB.NET 类,它有几个“字段”类型的公共属性。我想有一种方法可以遍历所有这些属性(每个属性都有一个)并在每个属性上执行特定任务。我认为也许最好的方法是创建一个列表(字段)并用该类的“字段”属性填充列表。我不知道如何动态地将属性添加到列表中,这样如果我将来添加属性,我就不必手动将它们输入到列表中。关于我如何做到这一点的任何想法?我尝试搜索并找到了一些使用反射的示例,但我只能弄清楚如何获取属性的名称而不是属性本身。
下面是一个类的例子:
Public Class ticket
Public Property location As New field
Public Property user As New field
Public Property callType As New field
Public Property dateOfCall As New field
Public Property tech As New field
Public Property description As New field
Public Property myFields As New List(Of field)
'What if field had a property of value and I wanted to increment all of the fields in this class by one
Public Sub plusOne()
For Each x As field In myFields()
x.value += 1
Next
End Sub
End Class