Imports System.Reflection
Public Class PropertyExample
Public Function GetMyProperties() As PropertyInfo()
Dim objProperties As PropertyInfo()
objProperties = Me.GetType.GetProperties(BindingFlags.Public Or BindingFlags.Instance)
Return objProperties
End Function
Public Property ThisWillBeRetrieved As String = "ThisWillBeRetrieved"
Private Property ThisWillNot As String = "ThisWillNot"
Public Shared Property NeitherWillThis As String = "NeitherWillThis"
Public Overrides Function ToString() As String
Return String.Join(",", GetMyProperties.Select(Function(pi) pi.Name).ToArray)
End Function
End Class
The Parameter of GetProperties defines which kinds of Properties will be returned by the function. Since we pass Public and Instance, the method will return only properties that are both public and non-shared. See The Flags attribute for and explanation on how Flag-enums can be combined.