private bool RecursiveSimplEquals(object left, object right, List<object> leftCompared, List<object> rightCompared)
{
leftCompared.Add(left);
rightCompared.Add(right);
if (left.GetType().Equals(right.GetType()))
{
foreach (var fieldDescriptor in this.Type.AllFieldDescriptors)
{
var leftDescribedValue = fieldDescriptor.GetValue(left);
var rightDescribedValue = fieldDescriptor.GetValue(right);
if (fieldDescriptor.IsComposite)
{
if (object.ReferenceEquals(leftDescribedValue, left) || Object.ReferenceEquals(rightDescribedValue,right))
{
// Circular refernces are fine, skip them / move on.
continue;
}
if (leftCompared.Contains(leftDescribedValue) || rightCompared.Contains(rightDescribedValue))
{
// Skip cycles.
continue;
}
var composite = new CompositeType(leftDescribedValue.GetType());
return composite.SimplEquals(leftDescribedValue, rightDescribedValue, leftCompared, rightCompared);
}
else
{
if (!fieldDescriptor.ContextSimplEquals(left,right))
{
return false;
}
}
}
return true;
}
else
{
return false;
}
}