Hi,
I have the following code:
Type type = typeof(T);
foreach (PropertyInfo pi in type.GetProperties(BindingFlags.Public | BindingFlags.Instance))
{
Type dataType = type.GetProperty(pi.Name).GetType();
object oldValue = type.GetProperty(pi.Name).GetValue(originalVals, null);
object newValue = type.GetProperty(pi.Name).GetValue(newVals, null);
if (oldValue != newValue)
{
// Do Something
}
}
The 2 variables originalVals and newVals that I am using are Linq2Sql classes. If 1 has an int field (intField) with an id of 999 and the other has the same field with the same value the oldValue != newValue comparison will pass because it will, obviously, use reference equality.
I'd like to know how to cast oldValue and newValue as the Type stored in dataType, something like:
((typeof(dataType)oldValue); or
(dataType)oldValue;
but this isn't working. Any suggestions?