0

私はこれらとして2つのクラスを持っています


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

ここで、プロパティ名のフルパスを渡すことができるLabelプロパティ名を使用してDataBoundコントロールを作成したいと思います。DataProperty

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

使い方はこんな感じになります

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

Reflectionを使用してこの値にアクセスする方法を提案してください。

明確にするために、静的またはインスタンス化された、任意の名前空間の任意のクラスの任意のプロパティにアクセスできるようにしたいと思います。したがって、で与えられているような宣言形式を使用することはできません

4

0 に答える 0