我有两节课
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" />
请建议一种使用反射访问此值的方法。
澄清一下,我希望能够访问任何命名空间的任何类中的任何属性,无论是静态的还是实例化的。因此我不能使用给出的声明格式