I need to compare two complex objects. My idea was to write a function that iterates over all properties of the object and the sub-objects and write a combination of the property name, the data type and the value in a string. The function returns the hash of this string.
So if the function returns the same hash for two objects the objects are equal. The function is fine. The problem is, that some properties are assigned with DateTime.Now.
tProduct.Timestamp = DataTime.Now;
tProduct.CreatedAt = DataTime.Now;
So if I call my function the string that is created slightly differs in those values.
Example:
//both objects are equal
var complexObject1 = Generate();
var complexObject2 = Generate();
var hash1 = GetHash(complexObject1); // uses string **xxx25.11.2021 15:11:51xxx** to hash
var hash2 = GetHash(complexObject2); // uses string **xxx25.11.2021 15:11:56xxx** to hash
I want to ignore those values in my function and I think I need reflection for this. The logic I want to implement is: If a property gets the value via DataTime.Now I will ignore it.
Aucun commentaire:
Enregistrer un commentaire