30-07-14, 12:15 AM
في Attributes و بشكل عام من الممكن ان تكتب الاسم كاملا أو ممكن أن تحذف كلمة ِAttribute من جملة الاستدعاء الخاصة به
يمكنك مراجعة الكود التالي و المأخوذ من اللينك التالي لمزيد من التوضيح
اللينك..............
يمكنك مراجعة الكود التالي و المأخوذ من اللينك التالي لمزيد من التوضيح
اللينك..............
كود :
<AttributeUsage(AttributeTargets.Method)> _
Public Class AnimalTypeAttribute
Inherits Attribute
' The constructor is called when the attribute is set.
Public Sub New(ByVal animal As Animal)
Me.thePet = animal
End Sub
' Keep a variable internally ...
Protected thePet As Animal
' .. and show a copy to the outside world.
Public Property Pet() As Animal
Get
Return thePet
End Get
Set(ByVal Value As Animal)
thePet = Value
End Set
End Property
End Class
Class AnimalTypeTestClass
<AnimalTypeAttribute(Animal.Dog)> _
Public Sub DogMethod()
End Sub
<AnimalType(Animal.Cat)> _
Public Sub CatMethod()
End Sub
<AnimalType(Animal.Bird)> _
Public Sub BirdMethod()
End Sub
End Class
Public Enum Animal
' Pets
Dog = 1
Cat
Bird
End Enum
