470,596 Members | 1,353 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,596 developers. It's quick & easy.

not possible to get propertyinfo for inherited private members?

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
Nov 20 '05 #1
2 1402
"Bob" <no****@nowhere.com> wrote in news:etKf4MCcEHA.796
@TK2MSFTNGP09.phx.gbl:
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.

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 20 '05 #2
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
"Bob" <no****@nowhere.com> wrote in message
news:et*************@TK2MSFTNGP09.phx.gbl...
Is this a bug? Expected behavior? Did I get the binding flags wrong?


Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.