public bool Equal(SecurityElement other)
{
if (other == null)
return false;
// Check if the tags are the same
if (!string.Equals(_tag, other._tag))
return false;
// Check if the text is the same
if (!string.Equals(_text, other._text))
return false;
// Check if the attributes are the same and appear in the same
// order.
if (_attributes == null || other._attributes == null)
{
if (_attributes != other._attributes)
return false;
}
else
{
int iMax = _attributes.Count;
Debug.Assert(iMax % 2 == 0, "Odd number of strings means the attr/value pairs were not added correctly");
// Maybe we can get away by only checking the number of attributes
if (iMax != other._attributes.Count)
return false;
for (int i = 0; i < iMax; i++)
{
string lhs = (string)_attributes[i];
string rhs = (string)other._attributes[i];
if (!string.Equals(lhs, rhs))
return false;
}
}
// Finally we must check the child and make sure they are
// equal and in the same order
if (_children == null || other._children == null)
{
if (_children != other._children)
return false;
}
else
{
// Maybe we can get away by only checking the number of children
if (_children.Count != other._children.Count)
return false;
ConvertSecurityElementFactories();
other.ConvertSecurityElementFactories();
IEnumerator lhs = _children.GetEnumerator();
IEnumerator rhs = other._children.GetEnumerator();
SecurityElement e1, e2;
while (lhs.MoveNext())
{
rhs.MoveNext();
e1 = (SecurityElement)lhs.Current;
e2 = (SecurityElement)rhs.Current;
if (e1 == null || !e1.Equal(e2))
return false;
}
}
return true;
}