当前位置: 首页>>代码示例>>C#>>正文


C# HtmlElement.Add方法代码示例

本文整理汇总了C#中HtmlElement.Add方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlElement.Add方法的具体用法?C# HtmlElement.Add怎么用?C# HtmlElement.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HtmlElement的用法示例。


在下文中一共展示了HtmlElement.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Add_HtmlObject

        public void Add_HtmlObject(bool isVoid)
        {
            HtmlElement parent = new HtmlElement("parent", isVoid);

            // Atribute
            HtmlAttribute attribute = new HtmlAttribute("attribute");
            parent.Add(attribute);
            Assert.Equal(parent, attribute.Parent);
            Assert.Equal(new HtmlAttribute[] { attribute }, parent.Attributes());

            if (!isVoid)
            {
                // Element
                HtmlElement element = new HtmlElement("element");
                parent.Add(element);
                Assert.Equal(parent, element.Parent);
                Assert.Equal(new HtmlElement[] { element }, parent.Elements());

                // Nodes
                HtmlComment comment = new HtmlComment("comment");
                parent.Add(comment);
                Assert.Equal(parent, comment.Parent);
                Assert.Equal(new HtmlObject[] { element, comment }, parent.Nodes());
            }
        }
开发者ID:hughbe,项目名称:html-generator,代码行数:25,代码来源:HtmlElement.AddTests.cs

示例2: Ancestors_IgnoresAttributes_IgnoresNodes

        public void Ancestors_IgnoresAttributes_IgnoresNodes()
        {
            HtmlElement parent = new HtmlElement("parent");
            HtmlElement element1 = new HtmlElement("element1");
            HtmlElement element2 = new HtmlElement("element2");
            parent.Add(element1);
            parent.Add(new HtmlAttribute("attribute"));
            parent.Add(new HtmlComment("comment"));
            parent.Add(element2);

            VerifyAncestors(element2, null, new HtmlElement[] { parent });
        }
开发者ID:hughbe,项目名称:html-generator,代码行数:12,代码来源:HtmlElement.ReadTests.cs

示例3: Add_ParamsHtmlObject_Empty

 public void Add_ParamsHtmlObject_Empty()
 {
     HtmlElement element = new HtmlElement("parent");
     element.Add(new HtmlObject[0]);
     Assert.Empty(element.Elements());
     Assert.Empty(element.Attributes());
 }
开发者ID:hughbe,项目名称:html-generator,代码行数:7,代码来源:HtmlElement.AddTests.cs

示例4: ReplaceAll_IEnumerableHtmlObject_AttributeToVoidElement

        public void ReplaceAll_IEnumerableHtmlObject_AttributeToVoidElement()
        {
            HtmlElement parent = new HtmlElement("parent", isVoid: true);
            parent.Add(new HtmlAttribute("attribute"));

            HtmlAttribute[] attributes = new HtmlAttribute[] { new HtmlAttribute("attribute1"), new HtmlAttribute("attribute2") };
            parent.ReplaceAll((IEnumerable<HtmlObject>)attributes);
            Assert.Equal(attributes, parent.Attributes());
        }
开发者ID:hughbe,项目名称:html-generator,代码行数:9,代码来源:HtmlElement.ReplaceTests.cs

示例5: ReplaceAll_DuplicateElementInContents_ThrowsInvalidOperationException

        public void ReplaceAll_DuplicateElementInContents_ThrowsInvalidOperationException()
        {
            HtmlElement parent = new HtmlElement("parent");
            HtmlElement element = new HtmlElement("element");
            parent.Add(element);

            Assert.Throws<InvalidOperationException>(() => parent.ReplaceAll(new HtmlObject[] { element }));
            Assert.Throws<InvalidOperationException>(() => parent.ReplaceAll((IEnumerable<HtmlObject>)new HtmlObject[] { element }));
        }
开发者ID:hughbe,项目名称:html-generator,代码行数:9,代码来源:HtmlElement.ReplaceTests.cs

示例6: Add_IEnumerableHtmlObject_NonVoidElement

        public void Add_IEnumerableHtmlObject_NonVoidElement()
        {
            HtmlElement parent = new HtmlElement("parent");
            HtmlElement element = new HtmlElement("element");
            HtmlAttribute attribute = new HtmlAttribute("Attribute");
            parent.Add((IEnumerable<HtmlObject>)new HtmlObject[] { element, attribute });

            Assert.Equal(parent, element.Parent);
            Assert.Equal(parent, attribute.Parent);
            Assert.Equal(new HtmlObject[] { element }, parent.Elements());
            Assert.Equal(new HtmlAttribute[] { attribute }, parent.Attributes());
        }
开发者ID:hughbe,项目名称:html-generator,代码行数:12,代码来源:HtmlElement.AddTests.cs

示例7: Add_ParamsHtmlObject_VoidElement

        public void Add_ParamsHtmlObject_VoidElement()
        {
            HtmlElement element = new HtmlElement("parent", isVoid: true);
            HtmlAttribute attribute1 = new HtmlAttribute("attribute1");
            HtmlAttribute attribute2 = new HtmlAttribute("attribute2");
            element.Add(new HtmlObject[] { attribute1, attribute2 });

            Assert.Equal(element, attribute1.Parent);
            Assert.Equal(element, attribute2.Parent);
            Assert.Empty(element.Elements());
            Assert.Equal(new HtmlAttribute[] { attribute1, attribute2 }, element.Attributes());
        }
开发者ID:hughbe,项目名称:html-generator,代码行数:12,代码来源:HtmlElement.AddTests.cs

示例8: Ancestors_OneLayerOfElements_ReturnsExpected

        public void Ancestors_OneLayerOfElements_ReturnsExpected()
        {
            HtmlElement parent = new HtmlElement("parent");
            HtmlElement child1 = new HtmlElement("child1");
            HtmlElement child2 = new HtmlElement("child2");

            parent.Add(child1, child2);

            VerifyAncestors(child1, null, new HtmlElement[] { parent });
            VerifyAncestors(child1, "parent", new HtmlElement[] { parent });
            VerifyAncestors(child1, "PARENT", new HtmlElement[] { parent });
            VerifyAncestors(child1, "child1", new HtmlElement[0]);
            VerifyAncestors(child1, "no-such-element", new HtmlElement[0]);
        }
开发者ID:hughbe,项目名称:html-generator,代码行数:14,代码来源:HtmlElement.ReadTests.cs

示例9: Add_ParamsHtmlObject_NonVoidElement

        public void Add_ParamsHtmlObject_NonVoidElement()
        {
            HtmlElement parent = new HtmlElement("parent");
            HtmlElement element = new HtmlElement("element");
            HtmlAttribute attribute = new HtmlAttribute("attribute");
            HtmlComment comment = new HtmlComment("comment");
            parent.Add(new HtmlObject[] { element, attribute, comment });

            Assert.Equal(parent, element.Parent);
            Assert.Equal(parent, attribute.Parent);
            Assert.Equal(new HtmlObject[] { element }, parent.Elements());
            Assert.Equal(new HtmlAttribute[] { attribute }, parent.Attributes());
            Assert.Equal(new HtmlObject[] { element, comment }, parent.Nodes());
        }
开发者ID:hughbe,项目名称:html-generator,代码行数:14,代码来源:HtmlElement.AddTests.cs

示例10: Ancestors_TwoLayersOfElements_ReturnsExpected

        public void Ancestors_TwoLayersOfElements_ReturnsExpected()
        {
            HtmlElement parent = new HtmlElement("parent");
            HtmlElement child1 = new HtmlElement("child");
            HtmlElement grandchild1 = new HtmlElement("child");

            HtmlElement child2 = new HtmlElement("child");

            parent.Add(child1, child2);
            child1.Add(grandchild1);

            VerifyAncestors(grandchild1, null, new HtmlElement[] { child1, parent });
            VerifyAncestors(grandchild1, "child", new HtmlElement[] { child1 });
            VerifyAncestors(grandchild1, "parent", new HtmlElement[] { parent });
            VerifyAncestors(grandchild1, "PARENT", new HtmlElement[] { parent });
            VerifyAncestors(grandchild1, "no-such-element", new HtmlElement[0]);
        }
开发者ID:hughbe,项目名称:html-generator,代码行数:17,代码来源:HtmlElement.ReadTests.cs

示例11: Ancestors_ThreeLayersOfElements_ReturnsExpected

        public void Ancestors_ThreeLayersOfElements_ReturnsExpected()
        {
            HtmlElement parent = new HtmlElement("parent");
            HtmlElement child1 = new HtmlElement("child");
            HtmlElement grandchild1 = new HtmlElement("child");
            HtmlElement greatGrandchild = new HtmlElement("greatgrandchild");

            HtmlElement child2 = new HtmlElement("child");
            HtmlElement grandchild2 = new HtmlElement("grandchild");

            parent.Add(child1, child2);
            child1.Add(grandchild1);
            child2.Add(grandchild2);

            grandchild1.Add(greatGrandchild);

            VerifyAncestors(greatGrandchild, null, new HtmlElement[] { grandchild1, child1, parent });
            VerifyAncestors(greatGrandchild, "child", new HtmlElement[] { grandchild1, child1 });
            VerifyAncestors(greatGrandchild, "parent", new HtmlElement[] { parent });
            VerifyAncestors(greatGrandchild, "PARENT", new HtmlElement[] { parent });
            VerifyAncestors(greatGrandchild, "greatgrandchild", new HtmlElement[0]);
            VerifyAncestors(greatGrandchild, "any", new HtmlElement[0]);
        }
开发者ID:hughbe,项目名称:html-generator,代码行数:23,代码来源:HtmlElement.ReadTests.cs

示例12: ReplaceNodes_DuplicateElementInNodes_ThrowsInvalidOperationException

        public void ReplaceNodes_DuplicateElementInNodes_ThrowsInvalidOperationException()
        {
            HtmlElement parent = new HtmlElement("parent");
            HtmlElement element = new HtmlElement("element");
            parent.Add(element);

            Assert.Throws<InvalidOperationException>(() => parent.ReplaceNodes(new HtmlNode[] { element }));
            Assert.Throws<InvalidOperationException>(() => parent.ReplaceNodes((IEnumerable<HtmlNode>)new HtmlNode[] { element }));
        }
开发者ID:hughbe,项目名称:html-generator,代码行数:9,代码来源:HtmlElement.ReplaceTests.cs

示例13: ReplaceAttributes_IEnumerableHtmlAttribute_VoidElement

        public void ReplaceAttributes_IEnumerableHtmlAttribute_VoidElement()
        {
            HtmlElement parent = new HtmlElement("br", isVoid: true);
            parent.Add(new HtmlAttribute("attribute1"));

            HtmlAttribute[] attributes = new HtmlAttribute[] { new HtmlAttribute("attribute2"), new HtmlAttribute("c") };
            parent.ReplaceAttributes((IEnumerable<HtmlAttribute>)attributes);
            Assert.Equal(attributes, parent.Attributes());
        }
开发者ID:hughbe,项目名称:html-generator,代码行数:9,代码来源:HtmlElement.ReplaceTests.cs

示例14: ReplaceAttributes_ParamsHtmlAttribute_VoidElement

        public void ReplaceAttributes_ParamsHtmlAttribute_VoidElement()
        {
            HtmlElement parent = new HtmlElement("parent", isVoid: true);
            parent.Add(new HtmlAttribute("attribute"));

            HtmlAttribute[] attributes = new HtmlAttribute[] { new HtmlAttribute("attribute1"), new HtmlAttribute("attribute2") };
            parent.ReplaceAttributes(attributes);
            Assert.Equal(attributes, parent.Attributes());
        }
开发者ID:hughbe,项目名称:html-generator,代码行数:9,代码来源:HtmlElement.ReplaceTests.cs

示例15: Add_IEnumerableHtmlObject_VoidElement

        public void Add_IEnumerableHtmlObject_VoidElement()
        {
            HtmlElement parent = new HtmlElement("parent", isVoid: true);
            HtmlAttribute attribute1 = new HtmlAttribute("attribute1");
            HtmlAttribute attribute2 = new HtmlAttribute("attribute2");
            parent.Add((IEnumerable<HtmlObject>)new HtmlObject[] { attribute1, attribute2 });

            Assert.Equal(parent, attribute1.Parent);
            Assert.Equal(parent, attribute2.Parent);
            Assert.Empty(parent.Elements());
            Assert.Equal(new HtmlAttribute[] { attribute1, attribute2 }, parent.Attributes());
        }
开发者ID:hughbe,项目名称:html-generator,代码行数:12,代码来源:HtmlElement.AddTests.cs


注:本文中的HtmlElement.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。