private void ToString(string indent, object obj, Action<object, string> write)
{
write(obj, "<");
write(obj, _tag);
// If there are any attributes, plop those in.
if (_attributes != null && _attributes.Count > 0)
{
write(obj, " ");
int iMax = _attributes.Count;
Debug.Assert(iMax % 2 == 0, "Odd number of strings means the attr/value pairs were not added correctly");
for (int i = 0; i < iMax; i += 2)
{
string strAttrName = (string)_attributes[i];
string strAttrValue = (string)_attributes[i + 1];
write(obj, strAttrName);
write(obj, "=\"");
write(obj, strAttrValue);
write(obj, "\"");
if (i != _attributes.Count - 2)
{
write(obj, Environment.NewLine);
}
}
}
if (_text == null && (_children == null || _children.Count == 0))
{
// If we are a single tag with no children, just add the end of tag text.
write(obj, "/>");
write(obj, Environment.NewLine);
}
else
{
// Close the current tag.
write(obj, ">");
// Output the text
write(obj, _text);
// Output any children.
if (_children != null)
{
ConvertSecurityElementFactories();
write(obj, Environment.NewLine);
for (int i = 0; i < _children.Count; ++i)
{
((SecurityElement)_children[i]).ToString(string.Empty, obj, write);
}
}
// Output the closing tag
write(obj, "</");
write(obj, _tag);
write(obj, ">");
write(obj, Environment.NewLine);
}
}