-
AttributeUsage
Can someone explain to me why AttributeUsage is used in a Class scenario?
Thanks
Code:
<AttributeUsage(AttributeTargets.Parameter)> _
Public Class SqlParameterAttribute
Inherits Attribute
Private _name As String
Private _paramTypeDefined As Boolean
Private _paramType As SqlDbType
Private _size As Integer
Private _precision As Byte
Private _scale As Byte
Private _directionDefined As Boolean
Private _direction As ParameterDirection
etc.............
-
The Class is an Attribute, see how the name ends in Attribute and it inherits from the Attribute Class. So the AttributeUsage Attribute declares on what the attribute/class can be used on, in this case its only on parameters. That means if someone tries to apply that attribute to something other than a parameter it will give an error.