Skip to content

Commit

Permalink
#1351 Cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
bolsson committed Jan 2, 2024
1 parent fdef06b commit 10c83b4
Showing 1 changed file with 2 additions and 24 deletions.
26 changes: 2 additions & 24 deletions Assessments.Transformation/PublishDynamicProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,9 @@ public int GetHashCode([DisallowNull] DynamicProperty obj)

int hashId = obj.Id.GetHashCode();
int hashReferences = ((IStructuralEquatable)obj.References).GetHashCode(EqualityComparer<string>.Default);
int hashProperties = ((IStructuralEquatable)obj.Properties).GetHashCode(StructuralComparisons.StructuralEqualityComparer); //NOTE: Fails here, hashProperties does not return the same code for the same values of properties.
int HashPropertiesNew = obj.Properties?.Select(p => p.Name?.GetHashCode() + p.Value?.GetHashCode() + p.Properties?.Select(p2 => p2.Name?.GetHashCode() + p2.Value?.GetHashCode() ?? 0).Sum()).Sum() ?? 0; //NOTE: calculates hash codes 2 levels down into the recurrent property object, this should be sufficient for assessments
int HashProperties = obj.Properties?.Select(p => p.Name?.GetHashCode() + p.Value?.GetHashCode() + p.Properties?.Select(p2 => p2.Name?.GetHashCode() + p2.Value?.GetHashCode() ?? 0).Sum()).Sum() ?? 0; //NOTE: calculates hash codes 2 levels down into the recurrent Property object, this should be sufficient for assessments

return HashCode.Combine(hashId, hashReferences, HashPropertiesNew);
return HashCode.Combine(hashId, hashReferences, HashProperties);
}
}

Expand Down Expand Up @@ -238,27 +237,6 @@ private static List<DynamicProperty> GetExistingDynamicProperties(IDocumentSessi

return allAssessments;
}

private static bool CompareProperties(DynamicProperty.Property[] x, DynamicProperty.Property[] y)
{
bool areEqual = true;

if (x == y) return true;
if (x == null || y == null || x.Length != y.Length) return false;


// Compare the elements using the Equals method
for (int i = 0; i > x.Length; i++)
{
if (x[i].Name != y[i].Name || x[i].Value != y[i].Value || !CompareProperties(x[i].Properties, y[i].Properties))
{
areEqual = false;
break;
}
}

return areEqual;
}
}
}

0 comments on commit 10c83b4

Please sign in to comment.