Let's say I have a class with two public properties, one has a getter defined and the other is an auto implemented property (which creates a getter/setter internally)
Public ReadOnly Property PendingAdd As String
Get
Return m_pendingadd
End Get
End Property
'Auto Implemented Property
Public AuditorName As String
When using reflection and calling GetProperties(), I only get the property with the Get
defined, the auto implemented property does not get returned. How can I get both properties using reflection?
Dim lobjSiteType As Type = Me.GetType()
For Each pi As System.Reflection.PropertyInfo In lobjSiteType.GetProperties(System.Reflection.BindingFlags.Public Or System.Reflection.BindingFlags.Instance
'Do stuff
Next
Public AuditorName As String
is not a property
it's a class variable.
This is an auto property in VB.NET:
Property YourProperty As String
A property is considered public to reflection if it has at least one accessor that is public. Otherwise the property is considered private, and you must use BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static (in Visual Basic, combine the values using Or) to get it.
http://msdn.microsoft.com/en-us/library/kyaxdd3x%28v=vs.110%29.aspx
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.