Mam zajęcia.Jak przechodzić między wszystkimi właściwościami klasy?
Public Class Foo
Private _Name As String
Public Property Name() As String
Get
Return _Name
End Get
Set(ByVal value As String)
_Name = value
End Set
End Property
Private _Age As String
Public Property Age() As String
Get
Return _Age
End Get
Set(ByVal value As String)
_Age = value
End Set
End Property
Private _ContactNumber As String
Public Property ContactNumber() As String
Get
Return _ContactNumber
End Get
Set(ByVal value As String)
_ContactNumber = value
End Set
End Property
End Class
Chcę przejść przez właściwości powyższej klasy. eg;
Public Sub DisplayAll(ByVal Someobject As Foo)
For Each _Property As something In Someobject.Properties
Console.WriteLine(_Property.Name & "=" & _Property.value)
Next
End Sub
Btw, czy nie powinno być niektórych flag wiążących dla tej metody GetProperties? Podobnie jak "BindingFlags.Public | BindingFlags.GetProperty' lub coś takiego? – Svish
@Svish, masz rację :) Może użyć niektórych BindingFlags, ale są one opcjonalne. Prawdopodobnie chcesz Public Instancja. – Brannon
Wskazówka: Jeśli masz do czynienia z polami statycznymi, po prostu podaj tutaj wartość null: property.GetValue (null); – Seva