本文整理汇总了C#中Paragraph.ElementsBefore方法的典型用法代码示例。如果您正苦于以下问题:C# Paragraph.ElementsBefore方法的具体用法?C# Paragraph.ElementsBefore怎么用?C# Paragraph.ElementsBefore使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Paragraph
的用法示例。
在下文中一共展示了Paragraph.ElementsBefore方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OpenXmlElementTraversingMethodsTest
public void OpenXmlElementTraversingMethodsTest()
{
Paragraph para = new Paragraph();
Run r1 = para.AppendChild(new Run());
Bold b1 = r1.AppendChild(new RunProperties()).AppendChild(new Bold());
Text t1 = r1.AppendChild(new Text());
Run r2 = para.AppendChild(new Run());
r2.AppendChild(new Text());
Run r3 = para.AppendChild(new Run());
Assert.Equal(7, para.Descendants().Count());
Assert.Equal(3, r1.Descendants().Count());
Assert.Equal(1, r2.Descendants().Count());
Assert.Equal(0, r3.Descendants().Count());
Assert.Same(r1, para.Descendants().First());
Assert.Same(b1, para.Descendants().ElementAt(2));
Assert.Same(t1, para.Descendants().ElementAt(3));
Assert.Same(r2, para.Descendants().ElementAt(4));
Assert.Same(r3, para.Descendants().Last());
// ancestors
Assert.Equal(0, para.Ancestors().Count());
Assert.Equal(0, para.Ancestors<Body>().Count());
Assert.Equal(1, r1.Ancestors().Count());
Assert.Equal(1, r1.Ancestors<Paragraph>().Count());
Assert.Equal(0, r1.Ancestors<Body>().Count());
Assert.Equal(1, r3.Ancestors().Count());
Assert.Equal(1, r3.Ancestors<Paragraph>().Count());
Assert.Equal(0, r3.Ancestors<Body>().Count());
Assert.Equal(2, t1.Ancestors().Count());
Assert.Equal(1, t1.Ancestors<Paragraph>().Count());
Assert.Equal(0, t1.Ancestors<Body>().Count());
Assert.Equal(3, b1.Ancestors().Count());
Assert.Equal(1, b1.Ancestors<Paragraph>().Count());
Assert.Equal(1, b1.Ancestors<Run>().Count());
Assert.Equal(1, b1.Ancestors<RunProperties>().Count());
Assert.Equal(0, b1.Ancestors<Body>().Count());
Assert.Same(para, r1.Ancestors().First());
Assert.Same(para, r1.Ancestors<Paragraph>().First());
Assert.Same(r1, t1.Ancestors().First());
Assert.Same(para, t1.Ancestors().Last());
Assert.Same(r1, t1.Ancestors<Run>().First());
Assert.Same(para, t1.Ancestors<Paragraph>().First());
Assert.Same(para, b1.Ancestors().Last());
Assert.Same(r1, b1.Ancestors().ElementAt(1));
// IsBefore() / IsAfter()
Assert.False(para.IsBefore(para));
Assert.False(para.IsAfter(para));
Assert.False(r2.IsBefore(r2));
Assert.False(r2.IsAfter(r2));
Assert.True(para.IsBefore(r1));
Assert.False(para.IsAfter(r1));
Assert.True(para.IsBefore(b1));
Assert.False(para.IsAfter(b1));
Assert.False(r1.IsBefore(para));
Assert.True(r1.IsAfter(para));
Assert.False(r1.IsBefore(para));
Assert.True(r1.IsAfter(para));
Assert.True(r1.IsBefore(r2));
Assert.False(r1.IsAfter(r2));
Assert.False(r3.IsBefore(r1));
Assert.True(r3.IsAfter(r1));
Assert.False(b1.IsAfter(r2));
Assert.True(b1.IsBefore(r2));
Assert.True(r1.IsBefore(b1));
Assert.False(r1.IsAfter(b1));
Assert.True(b1.IsAfter(r1));
Assert.False(b1.IsBefore(r1));
Paragraph p2 = new Paragraph();
Run p2r1 = p2.AppendChild(new Run());
Assert.False(p2.IsBefore(para));
Assert.False(p2.IsAfter(para));
Assert.False(p2r1.IsAfter(para));
Assert.False(p2r1.IsBefore(para));
// ElementsBefore / ElementsAfter
Assert.False(para.ElementsBefore().Any());
Assert.False(para.ElementsAfter().Any());
Assert.True(r1.ElementsAfter().Any());
Assert.False(r1.ElementsBefore().Any());
Assert.False(r3.ElementsAfter().Any());
Assert.True(r3.ElementsBefore().Any());
Assert.True(r2.ElementsAfter().Any());
Assert.True(r2.ElementsBefore().Any());
Assert.Same(r1, r3.ElementsBefore().First());
Assert.Same(r2, r3.ElementsBefore().Last());
Assert.Same(r2, r1.ElementsAfter().First());
Assert.Same(r3, r1.ElementsAfter().Last());
Assert.False(b1.ElementsBefore().Any());
Assert.False(b1.ElementsAfter().Any());
//.........这里部分代码省略.........