本文整理汇总了C#中System.Xml.Linq.XComment.ElementsBeforeSelf方法的典型用法代码示例。如果您正苦于以下问题:C# XComment.ElementsBeforeSelf方法的具体用法?C# XComment.ElementsBeforeSelf怎么用?C# XComment.ElementsBeforeSelf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.Linq.XComment
的用法示例。
在下文中一共展示了XComment.ElementsBeforeSelf方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NodeElementsBeforeSelf
/// <summary>
/// Tests the ElementsBeforeSelf methods on Node.
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
//[Variation(Desc = "NodeElementsBeforeSelf")]
public void NodeElementsBeforeSelf()
{
XElement parent = new XElement("parent");
XElement child1a = new XElement("child1", new XElement("nested"));
XElement child1b = new XElement("child1", new XElement("nested"));
XElement child2a = new XElement("child2", new XElement("nested"));
XElement child2b = new XElement("child2", new XElement("nested"));
XComment comment = new XComment("this is a comment");
// If no parent, should not be any elements before it.
Validate.Enumerator(comment.ElementsBeforeSelf(), new XElement[0]);
parent.Add(child1a);
parent.Add(child1b);
parent.Add(child2a);
parent.Add(comment);
parent.Add(child2b);
Validate.Enumerator(
comment.ElementsBeforeSelf(),
new XElement[] { child1a, child1b, child2a });
Validate.Enumerator(
comment.ElementsBeforeSelf("child1"),
new XElement[] { child1a, child1b });
Validate.Enumerator(
child2b.ElementsBeforeSelf(),
new XElement[] { child1a, child1b, child2a });
Validate.Enumerator(
child2b.ElementsBeforeSelf("child2"),
new XElement[] { child2a });
}
示例2: NodeElementsBeforeSelf
public void NodeElementsBeforeSelf()
{
XElement parent = new XElement("parent");
XElement child1a = new XElement("child1", new XElement("nested"));
XElement child1b = new XElement("child1", new XElement("nested"));
XElement child2a = new XElement("child2", new XElement("nested"));
XElement child2b = new XElement("child2", new XElement("nested"));
XComment comment = new XComment("this is a comment");
// If no parent, should not be any elements before it.
Assert.Empty(comment.ElementsBeforeSelf());
parent.Add(child1a);
parent.Add(child1b);
parent.Add(child2a);
parent.Add(comment);
parent.Add(child2b);
Assert.Equal(new XElement[] { child1a, child1b, child2a }, comment.ElementsBeforeSelf());
Assert.Equal(comment.ElementsBeforeSelf("child1"), new XElement[] { child1a, child1b });
Assert.Equal(new XElement[] { child1a, child1b, child2a }, child2b.ElementsBeforeSelf());
Assert.Equal(new XElement[] { child2a }, child2b.ElementsBeforeSelf("child2"));
}