Hi,
I am messing around with custom attributes and may have understood the
concept a bit wrong:-
I have a simple class that has a few public properties that individually
have custom attributes. For example, each property has a custom attribute
class with one property defined, that of IsChanged.
I know how to initialise the attribute class with a value (i.e. define a
constructor with an argument and use that to assign to the IsChanged
property), but how do I access the attribute from within the class property
subsequently? The thing I would like to be able to do is modify the
attribute IsChanged when someone modifies the class property. Further to
that, I want to be able to check on those attributes later on in other
routines within the same class.
Sample code:-
Imports System.Reflecti on
<AttributeUsage (AttributeTarge ts.Property)> _
Class MyAttribute
Inherits Attribute
Private _isChanged As String
Public Property IsChanged() As String
Get
Return _isChanged
End Get
Set(ByVal Value As String)
_isChanged = Value
End Set
End Property
Sub New(ByVal isChanged As String)
_isChanged = isChanged
End Sub
End Class
Class TestAttr
Private _testProperty As String
<MyAttribute("N o")> _
Public Property testProperty() As String
Get
Return _testProperty
End Get
Set(ByVal Value As String)
_testProperty = Value
' set the isChanged attribute to Yes
End Set
End Property
Sub checkTestProper ty()
'check isChanged and do something based upon value
End Sub
End Class
Can anyone help?
Cheers
Dan
I am messing around with custom attributes and may have understood the
concept a bit wrong:-
I have a simple class that has a few public properties that individually
have custom attributes. For example, each property has a custom attribute
class with one property defined, that of IsChanged.
I know how to initialise the attribute class with a value (i.e. define a
constructor with an argument and use that to assign to the IsChanged
property), but how do I access the attribute from within the class property
subsequently? The thing I would like to be able to do is modify the
attribute IsChanged when someone modifies the class property. Further to
that, I want to be able to check on those attributes later on in other
routines within the same class.
Sample code:-
Imports System.Reflecti on
<AttributeUsage (AttributeTarge ts.Property)> _
Class MyAttribute
Inherits Attribute
Private _isChanged As String
Public Property IsChanged() As String
Get
Return _isChanged
End Get
Set(ByVal Value As String)
_isChanged = Value
End Set
End Property
Sub New(ByVal isChanged As String)
_isChanged = isChanged
End Sub
End Class
Class TestAttr
Private _testProperty As String
<MyAttribute("N o")> _
Public Property testProperty() As String
Get
Return _testProperty
End Get
Set(ByVal Value As String)
_testProperty = Value
' set the isChanged attribute to Yes
End Set
End Property
Sub checkTestProper ty()
'check isChanged and do something based upon value
End Sub
End Class
Can anyone help?
Cheers
Dan
Comment