not possible to get propertyinfo for inherited private members?

B

Bob

Is this a bug? Expected behavior? Did I get the binding flags wrong?

Bob

--------------------

Imports System.Reflection

Module Main

Public Sub main()
Dim b As BindingFlags = BindingFlags.NonPublic Or _
BindingFlags.Public Or BindingFlags.Instance
GetProperties(GetType(foo), b)
GetProperties(GetType(foo2), b)
End Sub

Private Sub GetProperties(ByVal t As Type, ByVal b As BindingFlags)
Dim str As String
For Each p As PropertyInfo In t.GetProperties(b)
str &= p.Name & vbCrLf
Next
MsgBox(str)
End Sub

End Module

Public Class foo
Private _testpublic As String
Public Property testpublic() As String
Get
Return _testpublic
End Get
Set(ByVal Value As String)
_testpublic = Value
End Set
End Property
Private _testprivate As String
Private Property testprivate() As String
Get
Return _testprivate
End Get
Set(ByVal Value As String)
_testprivate = Value
End Set
End Property
End Class

Public Class foo2
Inherits foo

End Class
 
L

Lucas Tam

Is this a bug? Expected behavior? Did I get the binding flags wrong?

Your properties are declared as private, so you can't access them.

If you want inherited classes to be able to access "private" properties,
use Protected instead. If you need more access, you can use Friend as well.
 
B

Bob

Duh, naturally Private isn't accessible to inheritors. I can just use
DeclaredOnly and walk up the inheritance chain until I hit Object, Control,
or UserControl...

Bob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top