M
Marc Robitaille
Hello,
I have this Field attribut class and a Client class that uses this Attribut
Class
<AttributeUsage(AttributeTargets.Property)> _
Public Class Field
Inherits Attribute
Private _FieldName As String
Private _Changed As Boolean
Public Sub New(ByVal changed As Boolean, ByVal fieldName As String)
_Changed = changed
_FieldName = fieldName
End Sub
Public Property FieldName() As String
Get
Return _FieldName
End Get
Set(ByVal value As String)
_FieldName = value
End Set
End Property
Public Property Changed() As Boolean
Get
Return _Changed
End Get
Set(ByVal value As Boolean)
_Changed = value
End Set
End Property
End Class
Public Class Client
Private _name As String
<Field(False, "name")> _
Public Property Name() As String
Get
Return _name
End Get
Set(ByVal value As String)
If value <> _name Then
Dim oType As Type = Me.GetType
Dim oPropertyInfo As PropertyInfo =
oType.GetProperty("Name")
Dim oAllAttributes As Field()
oAllAttributes =
oPropertyInfo.GetCustomAttributes(GetType(Field), False)
For Each oAttribute As Field In oAllAttributes
oAttribute.Changed = True
Exit For
Next
_name = value
End If
End Set
End Property
End Class
In the click event of a button I have this
Dim x as new Client
x.Name = "My name"
x.Name = "Your name"
What I want to do is to use the Changed property of my Field attribut class
to tell me that the Name property has changed or not. With this, I want to
build the SQL update string with only the fields that the Changed attribut
is set to True. It doesn't work :-( The changed property is allways false.
What I do wrong? Is it possible to update the value of a property of an
attribut? if yes, how can I do this?
Thank you and hope that I am clear
Marc R.
I have this Field attribut class and a Client class that uses this Attribut
Class
<AttributeUsage(AttributeTargets.Property)> _
Public Class Field
Inherits Attribute
Private _FieldName As String
Private _Changed As Boolean
Public Sub New(ByVal changed As Boolean, ByVal fieldName As String)
_Changed = changed
_FieldName = fieldName
End Sub
Public Property FieldName() As String
Get
Return _FieldName
End Get
Set(ByVal value As String)
_FieldName = value
End Set
End Property
Public Property Changed() As Boolean
Get
Return _Changed
End Get
Set(ByVal value As Boolean)
_Changed = value
End Set
End Property
End Class
Public Class Client
Private _name As String
<Field(False, "name")> _
Public Property Name() As String
Get
Return _name
End Get
Set(ByVal value As String)
If value <> _name Then
Dim oType As Type = Me.GetType
Dim oPropertyInfo As PropertyInfo =
oType.GetProperty("Name")
Dim oAllAttributes As Field()
oAllAttributes =
oPropertyInfo.GetCustomAttributes(GetType(Field), False)
For Each oAttribute As Field In oAllAttributes
oAttribute.Changed = True
Exit For
Next
_name = value
End If
End Set
End Property
End Class
In the click event of a button I have this
Dim x as new Client
x.Name = "My name"
x.Name = "Your name"
What I want to do is to use the Changed property of my Field attribut class
to tell me that the Name property has changed or not. With this, I want to
build the SQL update string with only the fields that the Changed attribut
is set to True. It doesn't work :-( The changed property is allways false.
What I do wrong? Is it possible to update the value of a property of an
attribut? if yes, how can I do this?
Thank you and hope that I am clear
Marc R.