本文整理汇总了C#中System.Xml.Linq.XComment.NodesBeforeSelf方法的典型用法代码示例。如果您正苦于以下问题:C# XComment.NodesBeforeSelf方法的具体用法?C# XComment.NodesBeforeSelf怎么用?C# XComment.NodesBeforeSelf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.Linq.XComment
的用法示例。
在下文中一共展示了XComment.NodesBeforeSelf方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NodeContentBeforeSelf
/// <summary>
/// Tests the ContentBeforeSelf method on Node.
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
//[Variation(Desc = "NodeContentBeforeSelf")]
public void NodeContentBeforeSelf()
{
XElement parent = new XElement("parent");
XComment child = new XComment("Self is a comment");
XComment comment1 = new XComment("Another comment");
XComment comment2 = new XComment("Yet another comment");
XElement element1 = new XElement("childelement", new XElement("nested"), new XAttribute("foo", "bar"));
XElement element2 = new XElement("childelement2", new XElement("nested"), new XAttribute("foo", "bar"));
XAttribute attribute = new XAttribute("attribute", "value");
// If no parent, should not be any content before it.
Validate.Enumerator(child.NodesBeforeSelf(), new XNode[0]);
// Add some content, including the child, and validate.
parent.Add(attribute);
parent.Add(comment1);
parent.Add(element1);
parent.Add(child);
parent.Add(comment2);
parent.Add(element2);
Validate.Enumerator(
child.NodesBeforeSelf(),
new XNode[] { comment1, element1 });
}
示例2: NodeAllContentBeforeSelf
/// <summary>
/// Tests the AllContentBeforeSelf method on Node.
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
//[Variation(Desc = "NodeAllContentBeforeSelf")]
public void NodeAllContentBeforeSelf()
{
XElement parent = new XElement("parent");
XComment child = new XComment("Self is a comment");
XComment comment1 = new XComment("Another comment");
XComment comment2 = new XComment("Yet another comment");
XElement element1 = new XElement("childelement", new XElement("nested"), new XAttribute("foo", "bar"));
XElement element2 = new XElement("childelement2", new XElement("nested"), new XAttribute("foo", "bar"));
XAttribute attribute = new XAttribute("attribute", "value");
// If no parent, should not be any content before it.
Validate.Enumerator<XNode>(child.NodesBeforeSelf(), new XNode[0]);
// Add child to parent. Should still be no content before it.
// Attributes are not content.
parent.Add(attribute);
parent.Add(child);
Validate.Enumerator<XNode>(child.NodesBeforeSelf(), new XNode[0]);
// Add more children and validate.
parent.Add(comment1);
parent.Add(element1);
Validate.Enumerator<XNode>(child.NodesBeforeSelf(), new XNode[0]);
parent.AddFirst(element2);
parent.AddFirst(comment2);
Validate.Enumerator<XNode>(child.NodesBeforeSelf(), new XNode[] { comment2, element2 });
}