public NesterBase <T> ThenAppendChild(string name, int indentSize = 2) { if (IsTag) { var el = new NesterBase <T>(name, true, indentSize) { Parent = this }; Children.Add(el); return(el); } if (Parent == null) { throw new Exception("You can't append to non tag with no parent"); } return(Parent.AppendChild(name, true, indentSize)); }
public NesterBase <T> AppendChild(string name, bool isTag = true, int indentSize = 2) { var el = new NesterBase <T>(name, isTag, indentSize); if (IsTag) { el.Parent = this; Children.Add(el); return(this); } // if no parent and this is not a tag we must throw an error if (Parent == null) { throw new Exception("You can't append to non tag with no parent"); } el = Parent.AppendChild(name, isTag, indentSize); return(this); }
public NesterBase <T> ThenAppendChild(string name, out NesterBase <T> element, bool isTag = true, int indentSize = 2) { if (IsTag) { element = new NesterBase <T>(name, isTag, indentSize) { Parent = this }; Children.Add(element); return(element); } if (Parent == null) { throw new Exception("You can't append to non tag with no parent"); } Parent.AppendChild(name, out element, isTag, indentSize); return(element); }
// pass current element private string ToStringImp(int indentLevel, NesterBase <T> current) { var sb = new StringBuilder(); var indent = indentTo(indentLevel * current.IndentSize); if (IsTag) { sb.AppendLine($"{indent}<{current.Name}>"); foreach (var child in current.Children) { sb.Append(child.ToStringImplementation(indentLevel + 1, current)); } sb.AppendLine($"{indent}</{current.Name}>"); } else { sb.AppendLine($"{indent}{current.Name}"); } return(sb.ToString()); }
public NesterBase <T> AppendText(string text, out NesterBase <T> element, int indentSize = 2) { return(AppendChild(text, out element, false, indentSize)); }