By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,524 Members | 1,593 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,524 IT Pros & Developers. It's quick & easy.

not possible to get propertyinfo for inherited private members?

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
"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

P: n/a
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.