Bir dersim var.Bir sınıfın tüm özelliklerine nasıl erişilir?
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
Yukarıdaki sınıfın özellikleri arasında geçiş yapmak istiyorum. , ör.
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, bu GetProperties yöntemi için bazı bağlayıcı bayraklar olmamalıdır? BindingFlags.Public gibi | BindingFlags.GetProperty' veya bir şey? – Svish
@Svish, haklısın :) Bazı BindingFlags kullanabilir, ancak isteğe bağlıdır. Muhtemelen Kamu | Örnek. – Brannon
İpucu: Statik alanlarla uğraşıyorsanız, sadece buraya null iletin: property.GetValue (null); – Seva