I have these two classes as a test, one inherited by the other. The real code that the test is based on is a DLL so I don’t want to expose every property to the users of the DLL. I would like to be able to access the child’s properties from the parent via reflection.
Public Module App
Public Sub Main()
Dim child As New ChildClass()
child.Run()
End Sub
End Module
Public MustInherit Class ParentClass
Public Sub Run()
[GetType].GetProperty("ProtectedProperty").GetValue(Me).ToString()
[GetType].GetProperty("ProtectedFriendProperty").GetValue(Me).ToString()
[GetType].GetProperty("FriendProperty").GetValue(Me).ToString()
[GetType].GetProperty("PublicProperty").GetValue(Me).ToString()
End
End Sub
End Class
Public Class ChildClass
Inherits ParentClass
Protected Property ProtectedProperty As String = "Protected"
Protected Friend Property ProtectedFriendProperty As String = "ProtectedFriend"
Friend Property FriendProperty As String = "Friend"
Public Property PublicProperty As String = "Public"
End Class
I would have expected any of the Friend properties to be accessible from the parent, but only the Public property doesn’t throw an error. Is there something I’m missing?