E
ECathell
I have a routine that compares 2 intances of the same object to see if there are any changes. The problem is that even though there are no changes, it tells me there are. I have even tried running a new routine that shows a messagebox with both objects' property values. below is my code.
this is the actual comparison code:
Dim Properties() As PropertyInfo = pType.GetProperties(BindingFlags.Public Or BindingFlags.Instance)
Dim PropertyItem As PropertyInfo
For Each PropertyItem In Properties
If ischanged = False Then
With PropertyItem
Dim o1 As New Object''These are just for testing and will be returned to refactored code
Dim o2 As New Object''These are just for testing and will be returned to refactored code
o1 = .GetValue(obj, Nothing)''These are just for testing and will be returned to refactored code
o2 = .GetValue(obj_original, Nothing)''These are just for testing and will be returned to refactored code
'TODO Comment These Out
Debug.WriteLine(String.Format("Property Name: {0} PropertyType:{1}", PropertyItem.Name, PropertyItem.PropertyType))
Debug.WriteLine(String.Format(" Name {0}", .Name))
Debug.WriteLine(String.Format(" New Value {0}", o1))
Debug.WriteLine(String.Format("Original Value {0}", o2))
'Debug.WriteLine(String.Format(" isChanged {0}", ischanged.ToString))
Debug.WriteLine(Environment.NewLine)
If Not o1.Equals(o2) Then
ischanged = True
End If
End With
End If
Next
This is the code that I validate with first: it displays the information properly.
Private Shared Sub validateValues(ByVal obj As Object, ByVal obj_original As Object, ByVal ptype As Type)
Dim s As New StringBuilder
Dim Properties() As PropertyInfo = ptype.GetProperties(BindingFlags.Public Or BindingFlags.Instance)
Dim PropertyItem As PropertyInfo
For Each PropertyItem In Properties
With PropertyItem
s.AppendFormat("Property Name:{0} CurrentValue:{1} OriginalValue:{1}", .Name, .GetValue(obj, Nothing), ..GetValue(obj_original, Nothing))
s.Append(Environment.NewLine)
End With
Next
MessageBox.Show(s.ToString)
End Sub
this is the actual comparison code:
Dim Properties() As PropertyInfo = pType.GetProperties(BindingFlags.Public Or BindingFlags.Instance)
Dim PropertyItem As PropertyInfo
For Each PropertyItem In Properties
If ischanged = False Then
With PropertyItem
Dim o1 As New Object''These are just for testing and will be returned to refactored code
Dim o2 As New Object''These are just for testing and will be returned to refactored code
o1 = .GetValue(obj, Nothing)''These are just for testing and will be returned to refactored code
o2 = .GetValue(obj_original, Nothing)''These are just for testing and will be returned to refactored code
'TODO Comment These Out
Debug.WriteLine(String.Format("Property Name: {0} PropertyType:{1}", PropertyItem.Name, PropertyItem.PropertyType))
Debug.WriteLine(String.Format(" Name {0}", .Name))
Debug.WriteLine(String.Format(" New Value {0}", o1))
Debug.WriteLine(String.Format("Original Value {0}", o2))
'Debug.WriteLine(String.Format(" isChanged {0}", ischanged.ToString))
Debug.WriteLine(Environment.NewLine)
If Not o1.Equals(o2) Then
ischanged = True
End If
End With
End If
Next
This is the code that I validate with first: it displays the information properly.
Private Shared Sub validateValues(ByVal obj As Object, ByVal obj_original As Object, ByVal ptype As Type)
Dim s As New StringBuilder
Dim Properties() As PropertyInfo = ptype.GetProperties(BindingFlags.Public Or BindingFlags.Instance)
Dim PropertyItem As PropertyInfo
For Each PropertyItem In Properties
With PropertyItem
s.AppendFormat("Property Name:{0} CurrentValue:{1} OriginalValue:{1}", .Name, .GetValue(obj, Nothing), ..GetValue(obj_original, Nothing))
s.Append(Environment.NewLine)
End With
Next
MessageBox.Show(s.ToString)
End Sub