T
Theo
Hi,
i created a custom attribute that accepts an argument in the constructor to fill a property. The constructor is supposed to be called when then attribute is set but that doesn't seem to happen.
Sample code:
<System.AttributeUsage(System.AttributeTargets.All, AllowMultiple:=True)> _
Public Class CustomAtt
Inherits System.Attribute
Public Sub New(ByVal Arg As String)
Me.Arg = Arg
if Arg = string.empty then throw new exception
End Sub
Private _Arg As String
Public Property Arg() As String
Get
Return _Arg
End Get
Set(ByVal Value As String)
_Arg = Value
End Set
End Property
End Class
<CustomAtt("something")> _
Public Class SomeClass
Public Sub New()
'Do something
End Sub
End Class
Running this in debug mode i noticed that the debuger does not go through the constructor of the attribute and there is not exception even if pass an empty string parameter.
How can i make this work?
Regards,
Theodore
i created a custom attribute that accepts an argument in the constructor to fill a property. The constructor is supposed to be called when then attribute is set but that doesn't seem to happen.
Sample code:
<System.AttributeUsage(System.AttributeTargets.All, AllowMultiple:=True)> _
Public Class CustomAtt
Inherits System.Attribute
Public Sub New(ByVal Arg As String)
Me.Arg = Arg
if Arg = string.empty then throw new exception
End Sub
Private _Arg As String
Public Property Arg() As String
Get
Return _Arg
End Get
Set(ByVal Value As String)
_Arg = Value
End Set
End Property
End Class
<CustomAtt("something")> _
Public Class SomeClass
Public Sub New()
'Do something
End Sub
End Class
Running this in debug mode i noticed that the debuger does not go through the constructor of the attribute and there is not exception even if pass an empty string parameter.
How can i make this work?
Regards,
Theodore