【发布时间】:2019-01-10 16:11:45
【问题描述】:
我有一个如下所示的属性:
<DataElement(0, 4)>
Private Property RiffId As String
Get
Dim mb As MethodBase = MethodBase.GetCurrentMethod()
Dim de As DataElementAttribute = mb.GetCustomAttribute(Of DataElementAttribute)()
...
End Get
Set(value As String)
...
End Set
End Property
(这个项目是 VB,但非常欢迎 C# 答案。)
变量de 包含null/Nothing,因为该属性适用于整个属性,而不是mb 变量包含的getter。有没有一种方便直接的方法来获取“父”方法库,而无需获取 getter 的名称,剥离前导的“get_”,并搜索类的属性以获取属性的属性?我没有看到,但也许我忽略了它。
【问题讨论】:
-
你能解释一下为什么你需要它来这样工作吗?因为它看起来像是针对其他问题的 hack。
-
我想访问属性的属性。有这么不寻常吗?
-
Is that so unusual? -
这个问题 (stackoverflow.com/questions/3628630/…) 讨论了它。我很好奇。
标签: .net vb.net reflection