0

I've two classes as these


Namespace Business
    Public Class Core
        Public Shared ReadOnly Property Settings As DBManager.Settings
            Get
                Return DBManager.Settings.GetSettings
            End Get
        End Property
    End Class
End Namespace
Namespace DBManager
    Public Class Settings
        Private _Name As String
        Public Property Name As String
            Get
                Return _Name
            End Get
            Set(ByVal value As String)
                _Name = value
            End Set
        End Property

        Private _Title As String
        Public Property Title As String
            Get
                Return _Title
            End Get
            Set(ByVal value As String)
                _Title = value
            End Set
        End Property

        Public Shared Function GetSettings() As Settings
            Return New Settings With {.Name = "Website", .Title = "My Product Site"}
        End Function
    End Class
End Namespace

Now, I wish to create a DataBound Label control with a property name as DataProperty where I can pass the full path of the property name.

Namespace Application.Controls
    Public Class ExtendedLabel
        Inherits Label

        Public Property DataProperty As String
            Get
                If ViewState("DataProperty") Is Nothing Then
                    Return String.Empty
                Else
                    Return CStr(ViewState("DataProperty"))
                End If
            End Get
            Set(ByVal value As String)
                ViewState("DataProperty") = value
            End Set
        End Property


        Private Sub ExtendedLabel_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            If Not String.IsNullOrEmpty(DataProperty) Then
                Me.Text = GetReflectedValue()
            End If
        End Sub

        Private Function GetReflectedValue() As String
                        //'Need suggestion here
        End Function
    End Class
End Namespace

usage will be something like this

<cc:ExtendedLabel id="elName" runat="server" DataProperty="Business.Core.Settings.Name" />

Kindly suggest a way to access this value using Reflection.

Just to clarify, I want to be able to access any property in any class of any namespace, static or instantiated. Therefore I cannot use a declarative format as given in

Community
  • 1
  • 1
Mayank Raichura
  • 381
  • 1
  • 8
  • This was just asked a few minutes ago: http://stackoverflow.com/questions/12141149/get-value-of-a-property-by-its-path-in-asp-net/12141300#12141300 – Amiram Korach Aug 27 '12 at 11:55
  • Agreed. When I ran a search, SO return no replies matching my queries. Looks like I took quite a while to complete my question. – Mayank Raichura Aug 27 '12 at 12:07

0 Answers0