Click here to Skip to main content
15,936,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here a example of 2 Class:
Public NotInheritable Class test
        Inherits ObjectBase

        Private _Name As System.String

        Public Property [Name] As System.String
            Set(value As System.String)
                If _Name <> value Then
                    _Name = value
                End If
            End Set
                Return _Name
            End Get
        End Property
End Class

Public MustInherit Class ObjectBase
        Implements INotifyPropertyChanged

        Public Event PropertyChanged(sender As Object, e As System.ComponentModel.PropertyChangedEventArgs) Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged

        Public Sub NotifyPropertyChanged(Optional ByVal propertyName As String = Nothing)
                RaiseEvent PropertyChanged(Me, New System.ComponentModel.PropertyChangedEventArgs(propertyName))
            End If
        End Sub
End Class

The problem: in each class in property-set I must wrote "NotifyPropertyChanged()". Now I search a solution in class "ObjectBase" (with reflection), that call the "NotifyPropertyChanged()" after set-value for each property in class "test".
The idea is, to create a Sub "New" in class "Objectbase", that Add this function for each Property.

What I have tried:

In class "Objectbase" I have create a Sub "new" and create a simple array "SQLParameters" for the class with reflection:
Private SqlParameters As List(Of SqlParameter) = New List(Of SqlParameter)

Sub New()
    For Each _PropertyInfo As System.Reflection.PropertyInfo In Me.GetType.GetProperties
            For Each _Attribute As System.Attribute In System.Attribute.GetCustomAttributes(_PropertyInfo)
                    Dim _DatabaseColumn As DATABASE.Field = CType(_Attribute, DATABASE.Field)
                    SqlParameters.Add(New SqlParameter("@" & _DatabaseColumn.Name, _DatabaseColumn.SqlDbType))
End Sub

This works, but I have no idea to add the event after set for each property?!?!?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900