I think I’m having boxing issues
foreach(var p in item.GetType().GetProperties().
Where(p => p.GetValue(original, null) is ValueType))
{
var originalValue = p.GetValue(original, null);
var modifiedValue = p.GetValue(item, null);
if (!originalValue.Equals(modifiedValue))
kvpData.AppendFormat("{0}={1}&", p.Name, originalValue);
}
originalValue is never equal to modifiedValue, Im guessing it’s because they are boxed inside Object. But how do I fix it?
It is not a boxing issue.
Equalsis a virtual method, which the boxed value types override just fine.However, I am not sure what the issue is. Could it be that there aren’t actually any matching properties? Remember that
GetProperties()without any parameters will only return public properties. If the properties you need are private, you need to add someBindingFlags:(I’m assuming here that you don’t want static properties.)
Are you also sure that it is actually properties that you are after and not fields? Remember that if you declare something as
then it’s a field, whereas
is a property. If it’s actually fields you need, you need to use
GetFields()instead ofGetProperties()with the same binding flags.