Got it. I have to finish iteriating the PropertyType case statement to
include the types (unless someone else knows a better way). Here is the
code:
Public Overloads Sub UndoChange(ByVal PropertyName As String)
Try
'Find the row in the changes datatable with the property name
Dim drProperty As DataRow =
propertyChanges.Rows.Find(PropertyName)
'check to make sure we got something
If Not IsNothing(drProperty) Then
Dim userType As Type = Me.GetType
'Get the local property
Dim userProp As PropertyInfo =
userType.GetProperty(PropertyName)
Select Case userProp.PropertyType.Name.ToString
Case "String"
userProp.SetValue(Me,
drProperty.Item("OldValue").ToString, Nothing)
Case "Int32"
userProp.SetValue(Me, CInt(drProperty.Item("OldValue")),
Nothing)
End Select
'this has been reset, remove the row so we don't log a false
update
drProperty.Delete()
End If
Catch ex As Exception
End Try
End Sub
"Lloyd Sheen" <a@b.cwrote in message
news:uC**************@TK2MSFTNGP02.phx.gbl...
>
"John Wright" <ri***********@hotmail.comwrote in message
news:Oq**************@TK2MSFTNGP04.phx.gbl...
>>I want to create a method in my class where I can pass in a property name
and have it reset the property to the previous value. I have the method
that stores the properties last value, now I need the class that can
interate through the properties and reset the value. Something like this
Private Sub UndoChange (PropertyName as string)
'Get the old value
dim drProperty as DataRow = propertyChanges.Rows.Find(PropertyName)
If Not IsNothing (drProperty) then
'PseduoCode
'iterate throught the properties and reset the property (this is
the code I need)
...find property
[Property].Value = drProperty.Item("OldValue"))
End if
End Sub
Anyone have any ideas how to access the classes properties like this?
John
You need to use reflection. I have code but not where I am. Look up the
relection classes and it is easy. You get an instance of the object and
apply the reflection methods to obtain the properties. You can also set
the values of the properties using reflection.
Hope this helps
Lloyd Sheen