對於Class擴展中的方法,可以使用<Attributes>
嗎?可以在類擴展中設置屬性嗎?
這裏是A類
Public Class Goblin
Inherits Monster
Enum goblinsRole
Chief
Grount
End Enum
Public Property name As String
Public Property role As goblinsRole
Private healthPoints As Integer
Public Sub New(into As Integer)
healthPoints = into
End Sub
Public Sub hitBy(damage As Integer)
<...>
End Sub
<ValidationMethod()>
Public Function checkByTheWitchDoctor()
<...>
End Function
<ValidationMethod()>
Public Function isAlive()
<...>
End Function
End Class
下面是這個類的一個擴展名的
Module ModuleExtension
<ValidationMethod()>
<Extension()>
Public Sub PrintDateOfDeath(ByVal aGoblin As DomainModelFake.Goblin)
<...>
End Sub
<Extension()>
<ValidationMethod()>
Public Function smashedByAGrount(ByVal aGoblin As DomainModelFake.Goblin) As Boolean
<...>
End Function
End Module
當我使用反射來獲取被標記具有這種屬性的方法,我只得到位於A類定義中的方法列表中沒有位於擴展名中的方法。
在extenso,這意味着我只看到:
- checkByTheWitchDoctor()
- 的IsAlive()
但我不見:
- PrintDateOfDeath ()
- smashedByAGrount()
這是正常的反射行爲嗎?它不搜索擴展?
試試看,並附上代碼。 –
@Romil什麼讓你覺得我沒有嘗試? –