public void TestIndent() { var tag = new TagBuilder {IsIntended = true, Indentation = 4}; tag.StartTag("parent") .AddAttribute("parentproperty1", "true") .AddAttribute("parentproperty2", "5") .StartTag("child1") .AddAttribute("childproperty1", "c") .AddContent("childbody") .EndTag() .StartTag("child2") .AddAttribute("childproperty2", "c") .AddContent("childbody") .EndTag() .EndTag() .StartTag("script") .AddContent("$.scriptbody();") .EndTag(); Console.WriteLine(tag.ToString()); const string indented = @"<parent parentproperty1='true' parentproperty2='5'> <child1 childproperty1='c'> childbody </child1> <child2 childproperty2='c'> childbody </child2> </parent> <script> $.scriptbody(); </script>"; Assert.AreEqual(indented, tag.ToString()); }
public TagBuilder(string TagName, TagBuilder Parent) { _tagName = TagName; _parent = Parent; _level = Parent._level + 1; IsIntended = Parent.IsIntended; Indentation = Parent.Indentation; }
public TagBuilder StartTag(string TagName) { var tag = new TagBuilder(TagName, this); return tag; }