Ejemplo n.º 1
0
        internal protected virtual string ToMarkupProtected(string indent, bool xmlEncode = false)
        {
            string name, value;

            if (xmlEncode)
            {
                XElement elem = new XElement("e", Value);
                name  = XmlConvert.EncodeName(Name);
                value = string.IsNullOrEmpty(Value) ? Value : elem.LastNode.ToString();
            }
            else
            {
                name  = Name;
                value = Value;
            }

            if (ChildNodes.Count == 0 && string.IsNullOrEmpty(value))
            {
                return(indent + "<" + name + "/>\r\n");
            }
            if (ChildNodes.Count == 0)
            {
                return(indent + "<" + name + ">" + value + "</" + name + ">\r\n");
            }
            string s = indent + "<" + name + ">" + value + "\r\n";

            s  = ChildNodes.Aggregate(s, (current, item) => current + item.ToMarkupProtected(indent + "  ", xmlEncode));
            s += indent + "</" + name + ">\r\n";
            return(s);
        }