private String ToString(String indent)
        {
            StringBuilder sb = new StringBuilder();

            // First add the indent

            sb.Append(indent);

            // Add in the opening bracket and the tag.

            sb.Append("<");

            switch (m_type)
            {
            case SecurityElementType.Format:
                sb.Append("?");
                break;

            case SecurityElementType.Comment:
                sb.Append("!--");
                break;

            default:
                break;
            }

            sb.Append(m_strTag);

            // If there are any attributes, plop those in.

            if (m_lAttributes != null && m_lAttributes.Count > 0)
            {
                sb.Append(" ");

                for (int i = 0; i < m_lAttributes.Count; ++i)
                {
                    SecurityStringPair pair = (SecurityStringPair)m_lAttributes[i];

                    sb.Append(pair.m_strAttributeName);
                    sb.Append("=\"");
                    sb.Append(pair.m_strAttributeValue);
                    sb.Append("\"");

                    if (i != m_lAttributes.Count - 1)
                    {
                        if (m_type == SecurityElementType.Regular)
                        {
                            sb.Append(Environment.NewLine);
                            sb.Append(indent);
                            sb.Append(' ', m_strTag.Length + 2);
                        }
                        else
                        {
                            sb.Append(" ");
                        }
                    }
                }
            }

            if (m_strText == null && (m_lChildren == null || m_lChildren.Count == 0))
            {
                // If we are a single tag with no children, just add the end of tag text.

                switch (m_type)
                {
                case SecurityElementType.Comment:
                    sb.Append(" -->");
                    break;

                case SecurityElementType.Format:
                    sb.Append(" ?>");
                    break;

                default:
                    sb.Append("/>");
                    break;
                }
                sb.Append(Environment.NewLine);
            }
            else
            {
                // Close the current tag.

                sb.Append(">");

                // Output the text

                sb.Append(m_strText);

                // Output any children.

                if (m_lChildren != null)
                {
                    sb.Append(Environment.NewLine);

                    String childIndent = indent + s_strIndent;

                    IEnumerator enumerator = m_lChildren.GetEnumerator();

                    while (enumerator.MoveNext())
                    {
                        sb.Append(((SecurityElement)enumerator.Current).ToString(childIndent));
                    }

                    // In the case where we have children, the close tag will not be on the same line as the
                    // opening tag, so we need to indent.

                    sb.Append(indent);
                }

                // Output the closing tag

                sb.Append("</");
                sb.Append(m_strTag);
                sb.Append(">");
                sb.Append(Environment.NewLine);
            }

            return(sb.ToString());
        }
 internal SecurityStringPair(SecurityStringPair rhs)
 {
     m_strAttributeName  = rhs.m_strAttributeName;
     m_strAttributeValue = rhs.m_strAttributeValue;
 }
Example #3
0
 internal SecurityStringPair( SecurityStringPair rhs )            
 {                                               
     m_strAttributeName = rhs.m_strAttributeName;
     m_strAttributeValue = rhs.m_strAttributeValue;
 }