mercredi 14 mars 2018

Comparing PropertyInfo.GetValue result when the PropertyInfo.GetType is not string

I´m comparing some properties values from two instances of the same class.

var vinst = prop.GetValue(workinginstance, null);
var vref = prop.GetValue(reference, null );
if ( vinst != vref) {
            info = info + String.Format( "{0} differ", prop.Name );
            valid = false;
}

My test class have two string props and one int. When I compare the string values, because the string´s immutability, the results are fine: is the strings differ, the equality fails,if they are the same, equality test is true. But when the code compare the two int properties, the result is always false. It seems to me that I need some form of casting to the PropertyInfo.GetType(), but don´t know how to do it. Any help will be appreciated.





Aucun commentaire:

Enregistrer un commentaire